From 60c1184320e75a56b82e3a610e98a12c3bd2f1a9 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Tue, 27 Feb 2024 12:41:47 +0100 Subject: [PATCH 1/4] Revert "Angular: Reduce the warnings from `ts-loader` via stricter list of `includes`" --- .../application/template-csf/.storybook/tsconfig.json | 2 +- .../library/template-csf/.storybook/tsconfig.json | 2 +- .../template/stories/component-play.stories.ts | 4 +--- scripts/tasks/sandbox-parts.ts | 10 +--------- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/code/lib/cli/templates/angular/application/template-csf/.storybook/tsconfig.json b/code/lib/cli/templates/angular/application/template-csf/.storybook/tsconfig.json index 84d7e7424a2c..eb06864100d8 100644 --- a/code/lib/cli/templates/angular/application/template-csf/.storybook/tsconfig.json +++ b/code/lib/cli/templates/angular/application/template-csf/.storybook/tsconfig.json @@ -6,6 +6,6 @@ "resolveJsonModule": true }, "exclude": ["../src/test.ts", "../src/**/*.spec.ts"], - "include": ["../src/**/*.stories.*", "./preview.ts"], + "include": ["../src/**/*", "./preview.ts"], "files": ["./typings.d.ts"] } diff --git a/code/lib/cli/templates/angular/library/template-csf/.storybook/tsconfig.json b/code/lib/cli/templates/angular/library/template-csf/.storybook/tsconfig.json index 957791d5bf3f..59daf738abdb 100644 --- a/code/lib/cli/templates/angular/library/template-csf/.storybook/tsconfig.json +++ b/code/lib/cli/templates/angular/library/template-csf/.storybook/tsconfig.json @@ -6,6 +6,6 @@ "resolveJsonModule": true }, "exclude": ["../src/test.ts", "../src/**/*.spec.ts"], - "include": ["../src/**/*.stories.*", "./preview.ts"], + "include": ["../src/**/*", "./preview.ts"], "files": ["./typings.d.ts"] } diff --git a/code/lib/preview-api/template/stories/component-play.stories.ts b/code/lib/preview-api/template/stories/component-play.stories.ts index 08efe9847b1f..5eec8cb2e5cf 100644 --- a/code/lib/preview-api/template/stories/component-play.stories.ts +++ b/code/lib/preview-api/template/stories/component-play.stories.ts @@ -6,9 +6,7 @@ import { expect } from '@storybook/test'; export default { component: globalThis.Components.Pre, play: async ({ canvasElement, name }: PlayFunctionContext) => { - await expect( - JSON.parse(within(canvasElement as HTMLPreElement).getByTestId('pre').innerText) - ).toEqual({ + await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toEqual({ name, }); }, diff --git a/scripts/tasks/sandbox-parts.ts b/scripts/tasks/sandbox-parts.ts index cd7dc643a185..691f19b30f44 100644 --- a/scripts/tasks/sandbox-parts.ts +++ b/scripts/tasks/sandbox-parts.ts @@ -585,7 +585,7 @@ async function prepareAngularSandbox(cwd: string, templateName: string) { // Set tsConfig compilerOptions - const tsConfigPath = join(cwd, '.storybook', 'tsconfig.json'); + const tsConfigPath = join(cwd, 'tsconfig.json'); const tsConfigContent = readFileSync(tsConfigPath, { encoding: 'utf-8' }); // This does not preserve comments, but that shouldn't be an issue for sandboxes const tsConfigJson = JSON5.parse(tsConfigContent); @@ -594,14 +594,6 @@ async function prepareAngularSandbox(cwd: string, templateName: string) { tsConfigJson.compilerOptions.noPropertyAccessFromIndexSignature = false; tsConfigJson.compilerOptions.jsx = 'react'; tsConfigJson.compilerOptions.skipLibCheck = true; - tsConfigJson.compilerOptions.noImplicitAny = false; - tsConfigJson.compilerOptions.strict = false; - tsConfigJson.include = [ - ...tsConfigJson.include, - '../template-stories/**/*.stories.ts', - // This is necessary since template stories depend on globalThis.components, which Typescript can't look up automatically - '../src/stories/**/*', - ]; if (templateName === 'Angular CLI (Version 15)') { tsConfigJson.compilerOptions.paths = { From 40e0cea55b2a50d64181fa068641d51dc2cf3073 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Tue, 27 Feb 2024 12:52:21 +0100 Subject: [PATCH 2/4] Loosen tsconfig a bit for storybook --- scripts/tasks/sandbox-parts.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/tasks/sandbox-parts.ts b/scripts/tasks/sandbox-parts.ts index 691f19b30f44..b8876234ddf4 100644 --- a/scripts/tasks/sandbox-parts.ts +++ b/scripts/tasks/sandbox-parts.ts @@ -585,7 +585,7 @@ async function prepareAngularSandbox(cwd: string, templateName: string) { // Set tsConfig compilerOptions - const tsConfigPath = join(cwd, 'tsconfig.json'); + const tsConfigPath = join(cwd, '.storybook', 'tsconfig.json'); const tsConfigContent = readFileSync(tsConfigPath, { encoding: 'utf-8' }); // This does not preserve comments, but that shouldn't be an issue for sandboxes const tsConfigJson = JSON5.parse(tsConfigContent); @@ -594,6 +594,8 @@ async function prepareAngularSandbox(cwd: string, templateName: string) { tsConfigJson.compilerOptions.noPropertyAccessFromIndexSignature = false; tsConfigJson.compilerOptions.jsx = 'react'; tsConfigJson.compilerOptions.skipLibCheck = true; + tsConfigJson.compilerOptions.noImplicitAny = false; + tsConfigJson.compilerOptions.strict = false; if (templateName === 'Angular CLI (Version 15)') { tsConfigJson.compilerOptions.paths = { From 26545827fcec336a33fc9196fb0f76b25d84e638 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Tue, 27 Feb 2024 12:53:33 +0100 Subject: [PATCH 3/4] Add template typechecking --- scripts/tasks/sandbox-parts.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/tasks/sandbox-parts.ts b/scripts/tasks/sandbox-parts.ts index b8876234ddf4..196467aaa14e 100644 --- a/scripts/tasks/sandbox-parts.ts +++ b/scripts/tasks/sandbox-parts.ts @@ -597,6 +597,8 @@ async function prepareAngularSandbox(cwd: string, templateName: string) { tsConfigJson.compilerOptions.noImplicitAny = false; tsConfigJson.compilerOptions.strict = false; + tsConfigJson.include = [...tsConfigJson.include, '../template-stories/**/*.stories.ts']; + if (templateName === 'Angular CLI (Version 15)') { tsConfigJson.compilerOptions.paths = { '@angular-devkit/*': ['node_modules/@angular-devkit/*'], From 01d0f7f5f5458a84ed21467b5c9c20bb1c05c035 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Tue, 27 Feb 2024 14:00:49 +0100 Subject: [PATCH 4/4] Fix build sandboxes --- .../preview-api/template/stories/component-play.stories.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/lib/preview-api/template/stories/component-play.stories.ts b/code/lib/preview-api/template/stories/component-play.stories.ts index 5eec8cb2e5cf..08efe9847b1f 100644 --- a/code/lib/preview-api/template/stories/component-play.stories.ts +++ b/code/lib/preview-api/template/stories/component-play.stories.ts @@ -6,7 +6,9 @@ import { expect } from '@storybook/test'; export default { component: globalThis.Components.Pre, play: async ({ canvasElement, name }: PlayFunctionContext) => { - await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toEqual({ + await expect( + JSON.parse(within(canvasElement as HTMLPreElement).getByTestId('pre').innerText) + ).toEqual({ name, }); },