Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Re-Add Nuxt support #28607

Merged
merged 30 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b9bf7d3
Revert "Revert: Nuxt support"
valentinpalkovic Jul 15, 2024
ac0b619
Merge branch 'next' into revert-28479-revert/26884
ndelangen Aug 14, 2024
a729e4f
dedupe
ndelangen Aug 14, 2024
0356e44
fixes
ndelangen Aug 14, 2024
7849598
Merge branch 'next' into revert-28479-revert/26884
tobiasdiez Aug 22, 2024
846bf4b
add nuxt sandbox
tobiasdiez Aug 23, 2024
e78c4cc
Merge branch 'next' into revert-28479-revert/26884
valentinpalkovic Sep 10, 2024
00ffb6b
Update sandbox template for Nuxt v3 (Vite | TypeScript)
valentinpalkovic Sep 10, 2024
f434a98
Merge remote-tracking branch 'origin/next' into revert-28479-revert/2…
valentinpalkovic Oct 28, 2024
a4f3e0c
Fix sandbox generation for Nuxt
valentinpalkovic Oct 28, 2024
9439677
Refactor sandbox generation for Nuxt templates
valentinpalkovic Oct 28, 2024
4ca546b
Refactor parallelism values in CircleCI config to add Nuxt sandbox
valentinpalkovic Oct 28, 2024
7635ba7
Merge branch 'next' into revert-28479-revert/26884
valentinpalkovic Nov 1, 2024
1f8bcbb
Skip e2e tests for nuxt sandbox
valentinpalkovic Nov 1, 2024
19f21e0
Fix typings
valentinpalkovic Nov 1, 2024
bf7484a
Fix CI scripts
valentinpalkovic Nov 1, 2024
e8daf4e
Use vue3 template stories for sandbox creation
kasperpeulen Dec 2, 2024
dee3222
Run e2e tests for Nuxt
kasperpeulen Dec 2, 2024
d02250a
Fix parallelism
kasperpeulen Dec 2, 2024
31aee40
Merge remote-tracking branch 'origin/next' into revert-28479-revert/2…
kasperpeulen Dec 3, 2024
bf3a3ca
Adjust tests
kasperpeulen Dec 3, 2024
47b4b69
Merge branch 'next' into revert-28479-revert/26884
kasperpeulen Dec 3, 2024
e7f32c8
Add temporary workaround for Nuxt sandboxes
yannbf Dec 5, 2024
8b788b1
Merge branch 'next' into revert-28479-revert/26884
yannbf Dec 5, 2024
334d401
Merge remote-tracking branch 'origin/next' into revert-28479-revert/2…
kasperpeulen Dec 9, 2024
abd2d62
Fix parallelism
kasperpeulen Dec 9, 2024
1c0791e
Fix parallelism
kasperpeulen Dec 9, 2024
72c0fab
Merge branch 'next' into revert-28479-revert/26884
kasperpeulen Dec 13, 2024
f3b3e56
Disable react check for nuxt
kasperpeulen Dec 13, 2024
54ec63f
Merge branch 'next' into revert-28479-revert/26884
kasperpeulen Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -772,15 +772,15 @@ workflows:
requires:
- unit-tests
- create-sandboxes:
parallelism: 14
parallelism: 15
requires:
- build
- build-sandboxes:
parallelism: 14
parallelism: 15
requires:
- create-sandboxes
- chromatic-sandboxes:
parallelism: 11
parallelism: 12
requires:
- build-sandboxes
- e2e-production:
Expand All @@ -792,7 +792,7 @@ workflows:
requires:
- create-sandboxes
- test-runner-production:
parallelism: 9
parallelism: 10
requires:
- build-sandboxes
- vitest-integration:
Expand Down Expand Up @@ -847,15 +847,15 @@ workflows:
requires:
- unit-tests
- create-sandboxes:
parallelism: 20
parallelism: 21
requires:
- build
- build-sandboxes:
parallelism: 20
parallelism: 21
requires:
- create-sandboxes
- chromatic-sandboxes:
parallelism: 17
parallelism: 18
requires:
- build-sandboxes
- e2e-production:
Expand All @@ -867,7 +867,7 @@ workflows:
requires:
- create-sandboxes
- test-runner-production:
parallelism: 15
parallelism: 16
requires:
- build-sandboxes
- vitest-integration:
Expand Down Expand Up @@ -920,18 +920,18 @@ workflows:
requires:
- build
- create-sandboxes:
parallelism: 38
parallelism: 39
requires:
- build
# - smoke-test-sandboxes: # disabled for now
# requires:
# - create-sandboxes
- build-sandboxes:
parallelism: 38
parallelism: 39
requires:
- create-sandboxes
- chromatic-sandboxes:
parallelism: 35
parallelism: 36
requires:
- build-sandboxes
- e2e-production:
Expand All @@ -943,7 +943,7 @@ workflows:
requires:
- create-sandboxes
- test-runner-production:
parallelism: 33
parallelism: 34
requires:
- build-sandboxes
- vitest-integration:
Expand Down
5 changes: 3 additions & 2 deletions code/core/scripts/helpers/sourcefiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

import { GlobalRegistrator } from '@happy-dom/global-registrator';
import { isNotNil } from 'es-toolkit';

import { dedent, esbuild, getWorkspace, prettier } from '../../../../scripts/prepare/tools';
import { temporaryFile } from '../../src/common/utils/cli';
Expand All @@ -26,7 +27,7 @@ export const generateSourceFiles = async () => {
async function generateVersionsFile(prettierConfig: prettier.Options | null): Promise<void> {
const location = join(__dirname, '..', '..', 'src', 'common', 'versions.ts');

const workspace = await getWorkspace();
const workspace = (await getWorkspace()).filter(isNotNil);

const versions = JSON.stringify(
workspace
Expand Down Expand Up @@ -55,7 +56,7 @@ async function generateVersionsFile(prettierConfig: prettier.Options | null): Pr
}

async function generateFrameworksFile(prettierConfig: prettier.Options | null): Promise<void> {
const thirdPartyFrameworks = ['qwik', 'solid', 'react-rsbuild', 'vue3-rsbuild'];
const thirdPartyFrameworks = ['qwik', 'solid', 'nuxt', 'react-rsbuild', 'vue3-rsbuild'];
const location = join(__dirname, '..', '..', 'src', 'types', 'modules', 'frameworks.ts');
const frameworksDirectory = join(__dirname, '..', '..', '..', 'frameworks');

Expand Down
32 changes: 22 additions & 10 deletions code/core/src/cli/detect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ const MOCK_FRAMEWORK_FILES: {
},
},
},
{
name: ProjectType.NUXT,
files: {
'package.json': {
dependencies: {
nuxt: '^3.11.2',
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
},
{
name: ProjectType.NUXT,
files: {
'package.json': {
dependencies: {
// Nuxt projects may have Vue 3 as an explicit dependency
nuxt: '^3.11.2',
vue: '^3.0.0',
},
},
},
},
{
name: ProjectType.VUE3,
files: {
Expand Down Expand Up @@ -435,16 +457,6 @@ describe('Detect', () => {
expect(result).toBe(ProjectType.UNDETECTED);
});

// TODO(blaine): Remove once Nuxt3 is supported
it(`UNSUPPORTED for Nuxt framework above version 3.0.0`, () => {
const result = detectFrameworkPreset({
dependencies: {
nuxt: '3.0.0',
},
});
expect(result).toBe(ProjectType.UNSUPPORTED);
});

// TODO: The mocking in this test causes tests after it to fail
it('REACT_SCRIPTS for custom react scripts config', () => {
const forkedReactScriptsConfig = {
Expand Down
15 changes: 14 additions & 1 deletion code/core/src/cli/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ export async function detectBuilder(packageManager: JsPackageManager, projectTyp
}

// REWORK
if (webpackConfig || (dependencies.webpack && dependencies.vite !== undefined)) {
if (
webpackConfig ||
((dependencies.webpack || dependencies['@nuxt/webpack-builder']) &&
dependencies.vite !== undefined)
) {
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
commandLog('Detected webpack project. Setting builder to webpack')();
return CoreBuilder.Webpack5;
}
Expand All @@ -136,6 +140,8 @@ export async function detectBuilder(packageManager: JsPackageManager, projectTyp
case ProjectType.NEXTJS:
case ProjectType.EMBER:
return CoreBuilder.Webpack5;
case ProjectType.NUXT:
return CoreBuilder.Vite;
default:
const { builder } = await prompts(
{
Expand Down Expand Up @@ -205,6 +211,13 @@ export async function detectLanguage(packageManager: JsPackageManager) {
} else if (semver.lt(typescriptVersion, '3.8.0')) {
logger.warn('Detected TypeScript < 3.8, populating with JavaScript examples');
}
} else {
// No direct dependency on TypeScript, but could be a transitive dependency
// This is eg the case for Nuxt projects, which support a recent version of TypeScript
// Check for tsconfig.json (https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
if (existsSync('tsconfig.json')) {
language = SupportedLanguage.TYPESCRIPT_4_9;
}
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
}

return language;
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/cli/dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function getRendererDir(
) {
const externalFramework = externalFrameworks.find((framework) => framework.name === renderer);
const frameworkPackageName =
externalFramework?.renderer || externalFramework?.packageName || `@storybook/${renderer}`;
externalFramework?.packageName || externalFramework?.renderer || `@storybook/${renderer}`;

const packageJsonPath = join(frameworkPackageName, 'package.json');

Expand Down
1 change: 1 addition & 0 deletions code/core/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const frameworkToDefaultBuilder: Record<
'html-vite': CoreBuilder.Vite,
'html-webpack5': CoreBuilder.Webpack5,
nextjs: CoreBuilder.Webpack5,
nuxt: CoreBuilder.Vite,
'experimental-nextjs-vite': CoreBuilder.Vite,
'preact-vite': CoreBuilder.Vite,
'preact-webpack5': CoreBuilder.Webpack5,
Expand Down
25 changes: 18 additions & 7 deletions code/core/src/cli/project_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
SupportedRenderers as CoreSupportedFrameworks,
SupportedRenderers as CoreSupportedRenderers,
SupportedFrameworks,
} from '@storybook/core/types';

Expand All @@ -24,10 +24,16 @@ export type ExternalFramework = {
export const externalFrameworks: ExternalFramework[] = [
{ name: 'qwik', packageName: 'storybook-framework-qwik' },
{ name: 'solid', frameworks: ['storybook-solidjs-vite'], renderer: 'storybook-solidjs' },
{
name: 'nuxt',
packageName: '@storybook-vue/nuxt',
frameworks: ['@storybook-vue/nuxt'],
renderer: '@storybook/vue3',
},
];

/** @deprecated Please use `SupportedFrameworks` from `@storybook/types` instead */
export type SupportedRenderers = CoreSupportedFrameworks;
/** @deprecated Please use `SupportedRenderers` from `@storybook/types` instead */
export type SupportedRenderers = CoreSupportedRenderers;

export const SUPPORTED_RENDERERS: SupportedRenderers[] = [
'react',
Expand All @@ -51,6 +57,7 @@ export enum ProjectType {
WEBPACK_REACT = 'WEBPACK_REACT',
NEXTJS = 'NEXTJS',
VUE3 = 'VUE3',
NUXT = 'NUXT',
ANGULAR = 'ANGULAR',
EMBER = 'EMBER',
WEB_COMPONENTS = 'WEB_COMPONENTS',
Expand Down Expand Up @@ -120,6 +127,13 @@ export type TemplateConfiguration = {
* specific.
*/
export const supportedTemplates: TemplateConfiguration[] = [
{
preset: ProjectType.NUXT,
dependencies: ['nuxt'],
matcherFunction: ({ dependencies }) => {
return dependencies?.every(Boolean) ?? true;
},
},
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
{
preset: ProjectType.VUE3,
dependencies: {
Expand Down Expand Up @@ -241,10 +255,7 @@ export const supportedTemplates: TemplateConfiguration[] = [
// users an "Unsupported framework" message
export const unsupportedTemplate: TemplateConfiguration = {
preset: ProjectType.UNSUPPORTED,
dependencies: {
// TODO(blaine): Remove when we support Nuxt 3
nuxt: (versionRange) => eqMajor(versionRange, 3),
},
dependencies: {},
matcherFunction: ({ dependencies }) => {
return dependencies?.some(Boolean) ?? false;
},
Expand Down
1 change: 1 addition & 0 deletions code/core/src/common/utils/framework-to-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const frameworkToRenderer: Record<
sveltekit: 'svelte',
'vue3-vite': 'vue3',
'vue3-webpack5': 'vue3',
nuxt: 'vue3',
'web-components-vite': 'web-components',
'web-components-webpack5': 'web-components',
'react-rsbuild': 'react',
Expand Down
2 changes: 2 additions & 0 deletions code/core/src/types/modules/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type SupportedFrameworks =
| 'nextjs'
| 'preact-vite'
| 'preact-webpack5'
| 'react-native-web-vite'
| 'react-vite'
| 'react-webpack5'
| 'server-webpack5'
Expand All @@ -20,5 +21,6 @@ export type SupportedFrameworks =
| 'web-components-webpack5'
| 'qwik'
| 'solid'
| 'nuxt'
| 'react-rsbuild'
| 'vue3-rsbuild';
3 changes: 2 additions & 1 deletion code/core/src/types/modules/renderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type SupportedRenderers =
| 'html'
| 'web-components'
| 'server'
| 'solid';
| 'solid'
| 'nuxt';
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions code/lib/cli-storybook/src/sandbox-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,16 @@ const baseTemplates = {
},
skipTasks: ['e2e-tests-dev', 'bench'],
},
'nuxt-vite/default-ts': {
name: 'Nuxt v3 (Vite | TypeScript)',
script: 'npx nuxi init --packageManager yarn --gitInit false {{beforeDir}}',
expected: {
framework: '@storybook-vue/nuxt',
renderer: '@storybook/vue3',
builder: '@storybook/builder-vite',
},
skipTasks: ['e2e-tests', 'e2e-tests-dev', 'bench', 'vitest-integration'],
},
'html-webpack/default': {
name: 'HTML Latest (Webpack | JavaScript)',
script: 'yarn create webpack5-html {{beforeDir}}',
Expand Down Expand Up @@ -748,6 +758,7 @@ export const normal: TemplateKey[] = [
'react-vite/default-ts',
'angular-cli/default-ts',
'vue3-vite/default-ts',
'nuxt-vite/default-ts',
'lit-vite/default-ts',
'svelte-vite/default-ts',
'svelte-kit/skeleton-ts',
Expand Down
3 changes: 2 additions & 1 deletion code/lib/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@
],
"scripts": {
"check": "jiti ../../../scripts/prepare/check.ts",
"prep": "jiti ../../../scripts/prepare/bundle.ts"
"prep": "jiti ../../../scripts/prepare/bundle.ts",
"sb": "node ./bin/index.js"
},
"dependencies": {
"@storybook/core": "workspace:*"
Expand Down
31 changes: 31 additions & 0 deletions code/lib/create-storybook/src/generators/NUXT/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { baseGenerator } from '../baseGenerator';
import type { Generator } from '../types';

const generator: Generator = async (packageManager, npmOptions, options) => {
await baseGenerator(
packageManager,
npmOptions,
options,
'vue3',
{
extraPackages: async () => {
return ['@nuxtjs/storybook'];
},
installFrameworkPackages: false,
componentsDestinationPath: './components',
extraMain: {
stories: ['../components/**/*.mdx', '../components/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
},
},
'nuxt'
);
// Add nuxtjs/storybook to nuxt.config.js
await packageManager.runPackageCommand('nuxi', [
'module',
'add',
'@nuxtjs/storybook',
'--skipInstall',
]);
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
};

export default generator;
Loading