UNPKG

@nx/nuxt

Version:

The Nuxt plugin for Nx contains executors and generators for managing Nuxt applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Vitest, Playwright, Cypress, and Storybook. - Generators for applications, l

45 lines (44 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addVitest = addVitest; const devkit_1 = require("@nx/devkit"); const utils_1 = require("../../init/lib/utils"); const versions_1 = require("../../../utils/versions"); async function addVitest(tree, options) { (0, utils_1.addVitestTargetDefaults)(tree); const nxJson = (0, devkit_1.readNxJson)(tree); const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string' ? p === '@nx/nuxt/plugin' : p.plugin === '@nx/nuxt/plugin'); const { createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion); (0, devkit_1.ensurePackage)('@nx/vitest', versions_1.nxVersion); const { configurationGenerator } = await Promise.resolve().then(() => require('@nx/vitest/generators')); const vitestTask = await configurationGenerator(tree, { project: options.projectName, uiFramework: 'none', coverageProvider: 'v8', skipFormat: true, testEnvironment: 'jsdom', skipViteConfig: true, addPlugin: true, }, hasPlugin); createOrEditViteConfig(tree, { project: options.projectName, includeLib: false, includeVitest: true, testEnvironment: 'jsdom', imports: [`import vue from '@vitejs/plugin-vue'`], plugins: ['vue()'], // NOTE: Set to false to generate .ts instead of .mts because @nuxt/eslint-config // does not handle .mts files in its parser configuration. // See: https://github.com/nuxt/eslint/blob/v0.5.6/packages/eslint-config/src/legacy.ts#L6-L11 useEsmExtension: false, }, true, undefined, true); (0, devkit_1.updateJson)(tree, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => { json.compilerOptions ??= {}; json.compilerOptions.composite = true; json.include = ['.nuxt/nuxt.d.ts', ...(json.include ?? [])]; return json; }); return vitestTask; }