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

Open
wants to merge 16 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
14 changes: 10 additions & 4 deletions code/core/src/cli/project_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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' },
];

/** @deprecated Please use `SupportedFrameworks` from `@storybook/types` instead */
Expand Down Expand Up @@ -51,6 +52,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 +122,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 +250,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
1 change: 1 addition & 0 deletions code/core/src/types/modules/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,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,
'nuxt',
{
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