@nx/nuxt 0.0.0-pr-22179-271588f → 0.0.0-pr-26482-ebe2dba

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2023 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2024 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/migrations.json CHANGED
@@ -1,4 +1,23 @@
1
1
  {
2
2
  "generators": {},
3
- "packageJsonUpdates": {}
3
+ "packageJsonUpdates": {
4
+ "18.2.0": {
5
+ "version": "18.2.0-beta.0",
6
+ "packages": {
7
+ "@nuxt/eslint-config": {
8
+ "version": "~0.3.0-alpha.1",
9
+ "alwaysAddToPackageJson": false
10
+ }
11
+ }
12
+ },
13
+ "18.3.0": {
14
+ "version": "18.3.0-beta.2",
15
+ "packages": {
16
+ "@nuxt/eslint-config": {
17
+ "version": "~0.3.6",
18
+ "alwaysAddToPackageJson": false
19
+ }
20
+ }
21
+ }
22
+ }
4
23
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@nx/nuxt",
3
- "version": "0.0.0-pr-22179-271588f",
3
+ "version": "0.0.0-pr-26482-ebe2dba",
4
4
  "private": false,
5
- "description": "The Nuxt plugin for Nx contains executors and generators for managing Nuxt applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Vitest, Cypress, and Storybook.\n\n- Generators for applications, libraries, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
5
+ "description": "The Nuxt plugin for Nx contains executors and generators for managing Nuxt applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/nrwl/nx.git",
@@ -12,9 +12,10 @@
12
12
  "Monorepo",
13
13
  "Nuxt",
14
14
  "Web",
15
- "CLI"
15
+ "CLI",
16
+ "Front-end"
16
17
  ],
17
- "main": "./index.js",
18
+ "main": "./index",
18
19
  "typings": "./index.d.ts",
19
20
  "author": "Victor Savkin",
20
21
  "license": "MIT",
@@ -30,11 +31,11 @@
30
31
  "dependencies": {
31
32
  "tslib": "^2.3.0",
32
33
  "@nuxt/kit": "^3.10.0",
33
- "@nx/devkit": "0.0.0-pr-22179-271588f",
34
- "@nx/js": "0.0.0-pr-22179-271588f",
35
- "@nx/eslint": "0.0.0-pr-22179-271588f",
36
- "@nx/vue": "0.0.0-pr-22179-271588f",
37
- "@nx/vite": "0.0.0-pr-22179-271588f"
34
+ "@nx/devkit": "0.0.0-pr-26482-ebe2dba",
35
+ "@nx/js": "0.0.0-pr-26482-ebe2dba",
36
+ "@nx/eslint": "0.0.0-pr-26482-ebe2dba",
37
+ "@nx/vue": "0.0.0-pr-26482-ebe2dba",
38
+ "@nx/vite": "0.0.0-pr-26482-ebe2dba"
38
39
  },
39
40
  "peerDependencies": {},
40
41
  "publishConfig": {
@@ -14,6 +14,7 @@ const add_vitest_1 = require("./lib/add-vitest");
14
14
  const vue_1 = require("@nx/vue");
15
15
  const ensure_dependencies_1 = require("./lib/ensure-dependencies");
16
16
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
17
+ const node_child_process_1 = require("node:child_process");
17
18
  async function applicationGenerator(tree, schema) {
18
19
  const tasks = [];
19
20
  const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
@@ -24,13 +25,8 @@ async function applicationGenerator(tree, schema) {
24
25
  skipFormat: true,
25
26
  });
26
27
  tasks.push(jsInitTask);
27
- const nuxtInitTask = await (0, init_1.default)(tree, {
28
- ...options,
29
- skipFormat: true,
30
- });
31
- tasks.push(nuxtInitTask);
32
28
  tasks.push((0, ensure_dependencies_1.ensureDependencies)(tree, options));
33
- (0, devkit_1.addProjectConfiguration)(tree, options.name, {
29
+ (0, devkit_1.addProjectConfiguration)(tree, options.projectName, {
34
30
  root: options.appProjectRoot,
35
31
  projectType: 'application',
36
32
  sourceRoot: `${options.appProjectRoot}/src`,
@@ -69,11 +65,24 @@ async function applicationGenerator(tree, schema) {
69
65
  }));
70
66
  tasks.push(await (0, add_vitest_1.addVitest)(tree, options));
71
67
  }
68
+ const nuxtInitTask = await (0, init_1.default)(tree, {
69
+ ...options,
70
+ skipFormat: true,
71
+ });
72
+ tasks.push(nuxtInitTask);
72
73
  tasks.push(await (0, add_e2e_1.addE2e)(tree, options));
73
74
  if (options.js)
74
75
  (0, devkit_1.toJS)(tree);
75
76
  if (!options.skipFormat)
76
77
  await (0, devkit_1.formatFiles)(tree);
78
+ tasks.push(() => {
79
+ try {
80
+ (0, node_child_process_1.execSync)(`npx -y nuxi prepare`, { cwd: options.appProjectRoot });
81
+ }
82
+ catch (e) {
83
+ console.error(`Failed to run \`nuxi prepare\` in "${options.appProjectRoot}". Please run the command manually.`);
84
+ }
85
+ });
77
86
  tasks.push(() => {
78
87
  (0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
79
88
  });
@@ -13,7 +13,7 @@ export default defineNuxtConfig({
13
13
  typescript: {
14
14
  typeCheck: true,
15
15
  tsConfig: {
16
- extends: './tsconfig.app.json',
16
+ extends: '../tsconfig.app.json', // Nuxt copies this string as-is to the `./.nuxt/tsconfig.json`, therefore it needs to be relative to that directory
17
17
  },
18
18
  },
19
19
  imports: {
@@ -5,6 +5,6 @@ export default defineEventHandler((event) => {
5
5
  const name = q.name || 'World';
6
6
 
7
7
  return {
8
- message: `Hello ${name}`,
8
+ message: `Hello ${projectName}`,
9
9
  };
10
10
  });
@@ -20,12 +20,12 @@ async function addE2e(host, options) {
20
20
  directory: 'src',
21
21
  bundler: 'vite',
22
22
  skipFormat: true,
23
- devServerTarget: `${options.projectName}:serve`,
23
+ devServerTarget: `${options.projectName}:${options.e2eWebServerTarget}`,
24
24
  webServerCommands: {
25
- default: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.projectName}`,
25
+ default: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${options.e2eWebServerTarget} ${options.projectName}`,
26
26
  },
27
27
  ciWebServerCommand: `nx run ${options.projectName}:serve-static`,
28
- baseUrl: 'http://localhost:4200',
28
+ baseUrl: options.e2eWebServerAddress,
29
29
  jsx: true,
30
30
  addPlugin: true,
31
31
  });
@@ -46,8 +46,8 @@ async function addE2e(host, options) {
46
46
  js: false,
47
47
  linter: options.linter,
48
48
  setParserOptionsProject: options.setParserOptionsProject,
49
- webServerAddress: 'http://localhost:4200',
50
- webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.projectName}`,
49
+ webServerAddress: options.e2eWebServerAddress,
50
+ webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${options.e2eWebServerTarget} ${options.projectName}`,
51
51
  addPlugin: true,
52
52
  });
53
53
  }
@@ -12,7 +12,7 @@ async function addVitest(tree, options) {
12
12
  : p.plugin === '@nx/nuxt/plugin');
13
13
  const { createOrEditViteConfig, vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
14
14
  const vitestTask = await vitestGenerator(tree, {
15
- project: options.name,
15
+ project: options.projectName,
16
16
  uiFramework: 'none',
17
17
  coverageProvider: 'v8',
18
18
  skipFormat: true,
@@ -21,7 +21,7 @@ async function addVitest(tree, options) {
21
21
  addPlugin: true,
22
22
  }, hasPlugin);
23
23
  createOrEditViteConfig(tree, {
24
- project: options.name,
24
+ project: options.projectName,
25
25
  includeLib: false,
26
26
  includeVitest: true,
27
27
  testEnvironment: 'jsdom',
@@ -31,6 +31,7 @@ async function addVitest(tree, options) {
31
31
  (0, devkit_1.updateJson)(tree, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => {
32
32
  json.compilerOptions ??= {};
33
33
  json.compilerOptions.composite = true;
34
+ json.include = ['.nuxt/nuxt.d.ts', ...(json.include ?? [])];
34
35
  return json;
35
36
  });
36
37
  return vitestTask;
@@ -22,8 +22,26 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/nuxt:appl
22
22
  });
23
23
  options.rootProject = appProjectRoot === '.';
24
24
  options.projectNameAndRootFormat = projectNameAndRootFormat;
25
+ const nxJson = (0, devkit_1.readNxJson)(host);
26
+ let e2eWebServerTarget = 'serve';
27
+ if (nxJson.plugins) {
28
+ for (const plugin of nxJson.plugins) {
29
+ if (typeof plugin === 'object' &&
30
+ plugin.plugin === '@nx/nuxt/plugin' &&
31
+ plugin.options.serveTargetName) {
32
+ e2eWebServerTarget = plugin.options
33
+ .serveTargetName;
34
+ }
35
+ }
36
+ }
37
+ let e2ePort = 4200;
38
+ if (nxJson.targetDefaults?.[e2eWebServerTarget] &&
39
+ nxJson.targetDefaults?.[e2eWebServerTarget].options?.port) {
40
+ e2ePort = nxJson.targetDefaults?.[e2eWebServerTarget].options?.port;
41
+ }
25
42
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
26
43
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
44
+ const e2eWebServerAddress = `http://localhost:${e2ePort}`;
27
45
  const parsedTags = options.tags
28
46
  ? options.tags.split(',').map((s) => s.trim())
29
47
  : [];
@@ -34,11 +52,14 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/nuxt:appl
34
52
  appProjectRoot,
35
53
  e2eProjectName,
36
54
  e2eProjectRoot,
55
+ e2eWebServerAddress,
56
+ e2eWebServerTarget,
57
+ e2ePort,
37
58
  parsedTags,
38
59
  style: options.style ?? 'none',
39
60
  };
40
61
  normalized.unitTestRunner ??= 'vitest';
41
- normalized.e2eTestRunner = normalized.e2eTestRunner ?? 'cypress';
62
+ normalized.e2eTestRunner = normalized.e2eTestRunner ?? 'playwright';
42
63
  return normalized;
43
64
  }
44
65
  exports.normalizeOptions = normalizeOptions;
@@ -22,5 +22,8 @@ export interface NormalizedSchema extends Schema {
22
22
  appProjectRoot: string;
23
23
  e2eProjectName: string;
24
24
  e2eProjectRoot: string;
25
+ e2eWebServerAddress: string;
26
+ e2eWebServerTarget: string;
27
+ e2ePort: number;
25
28
  parsedTags: string[];
26
29
  }
@@ -49,10 +49,10 @@
49
49
  },
50
50
  "e2eTestRunner": {
51
51
  "type": "string",
52
- "enum": ["cypress", "playwright", "none"],
52
+ "enum": ["playwright", "cypress", "none"],
53
53
  "description": "Test runner to use for end to end (E2E) tests.",
54
54
  "x-prompt": "Which E2E test runner would you like to use?",
55
- "default": "cypress"
55
+ "default": "playwright"
56
56
  },
57
57
  "tags": {
58
58
  "type": "string",
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nuxtInitGenerator = void 0;
4
- const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
4
+ const devkit_1 = require("@nx/devkit");
5
+ const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
5
6
  const plugin_1 = require("../../plugins/plugin");
6
7
  const utils_1 = require("./lib/utils");
7
8
  async function nuxtInitGenerator(host, schema) {
8
- (0, utils_1.addPlugin)(host);
9
+ await (0, add_plugin_1.addPluginV1)(host, await (0, devkit_1.createProjectGraphAsync)(), '@nx/nuxt/plugin', plugin_1.createNodes, {
10
+ buildTargetName: ['build', 'nuxt:build', 'nuxt-build'],
11
+ serveTargetName: ['serve', 'nuxt:serve', 'nuxt-serve'],
12
+ }, schema.updatePackageScripts);
9
13
  let installTask = () => { };
10
14
  if (!schema.skipPackageJson) {
11
15
  installTask = (0, utils_1.updateDependencies)(host, schema);
12
16
  }
13
- if (schema.updatePackageScripts) {
14
- await (0, update_package_scripts_1.updatePackageScripts)(host, plugin_1.createNodes);
15
- }
16
17
  return installTask;
17
18
  }
18
19
  exports.nuxtInitGenerator = nuxtInitGenerator;
@@ -6,20 +6,23 @@ const path_1 = require("path");
6
6
  const cache_directory_1 = require("nx/src/utils/cache-directory");
7
7
  const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
8
  const fs_1 = require("fs");
9
- const executor_utils_1 = require("../utils/executor-utils");
10
9
  const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
11
10
  const js_1 = require("@nx/js");
12
- const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'nuxt.hash');
13
- const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
14
- const calculatedTargets = {};
11
+ const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
12
+ const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'nuxt.hash');
13
+ const targetsCache = readTargetsCache();
15
14
  function readTargetsCache() {
16
- return (0, devkit_1.readJsonFile)(cachePath);
15
+ return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
17
16
  }
18
- function writeTargetsToCache(targets) {
19
- (0, devkit_1.writeJsonFile)(cachePath, targets);
17
+ function writeTargetsToCache() {
18
+ const oldCache = readTargetsCache();
19
+ (0, devkit_1.writeJsonFile)(cachePath, {
20
+ ...oldCache,
21
+ ...targetsCache,
22
+ });
20
23
  }
21
24
  const createDependencies = () => {
22
- writeTargetsToCache(calculatedTargets);
25
+ writeTargetsToCache();
23
26
  return [];
24
27
  };
25
28
  exports.createDependencies = createDependencies;
@@ -34,18 +37,13 @@ exports.createNodes = [
34
37
  return {};
35
38
  }
36
39
  options = normalizeOptions(options);
37
- const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
38
- (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
39
- ]);
40
- const targets = targetsCache[hash]
41
- ? targetsCache[hash]
42
- : await buildNuxtTargets(configFilePath, projectRoot, options, context);
43
- calculatedTargets[hash] = targets;
40
+ const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
41
+ targetsCache[hash] ??= await buildNuxtTargets(configFilePath, projectRoot, options, context);
44
42
  return {
45
43
  projects: {
46
44
  [projectRoot]: {
47
45
  root: projectRoot,
48
- targets,
46
+ targets: targetsCache[hash],
49
47
  },
50
48
  },
51
49
  };
@@ -95,6 +93,8 @@ function serveStaticTarget(options) {
95
93
  buildTarget: `${options.buildStaticTargetName}`,
96
94
  staticFilePath: '{projectRoot}/dist',
97
95
  port: 4200,
96
+ // Routes are found correctly with serve-static
97
+ spa: false,
98
98
  },
99
99
  };
100
100
  return targetConfig;
@@ -118,25 +118,19 @@ function buildStaticTarget(buildStaticTargetName, namedInputs, buildOutputs, pro
118
118
  return targetConfig;
119
119
  }
120
120
  async function getInfoFromNuxtConfig(configFilePath, context, projectRoot) {
121
- const { loadNuxtConfig } = await (0, executor_utils_1.loadNuxtKitDynamicImport)();
122
- const config = await loadNuxtConfig({
123
- cwd: (0, devkit_1.joinPathFragments)(context.workspaceRoot, projectRoot),
124
- configFile: (0, path_1.basename)(configFilePath),
125
- });
121
+ // TODO(Colum): Once plugins are isolated we can go back to @nuxt/kit since each plugin will be run in its own worker.
122
+ const config = await (0, config_utils_1.loadConfigFile)((0, path_1.join)(context.workspaceRoot, configFilePath));
126
123
  return {
127
- buildDir: config?.buildDir,
124
+ buildDir: config?.buildDir ??
125
+ // Match .nuxt default build dir from '@nuxt/schema'
126
+ // See: https://github.com/nuxt/nuxt/blob/871404ae5673425aeedde82f123ea58aa7c6facf/packages/schema/src/config/common.ts#L117-L119
127
+ '.nuxt',
128
128
  };
129
129
  }
130
130
  function getOutputs(nuxtConfig, projectRoot) {
131
- let nuxtBuildDir = nuxtConfig?.buildDir;
132
- if (nuxtConfig?.buildDir && (0, path_1.basename)(nuxtConfig?.buildDir) === '.nuxt') {
133
- // if buildDir exists, it will be `something/something/.nuxt`
134
- // we want the "general" outputPath to be `something/something`
135
- nuxtBuildDir = nuxtConfig.buildDir.replace((0, path_1.basename)(nuxtConfig.buildDir), '');
136
- }
137
- const buildOutputPath = normalizeOutputPath(nuxtBuildDir, projectRoot);
131
+ const buildOutputPath = normalizeOutputPath(nuxtConfig?.buildDir, projectRoot);
138
132
  return {
139
- buildOutputs: [buildOutputPath],
133
+ buildOutputs: [buildOutputPath, '{projectRoot}/.output'],
140
134
  };
141
135
  }
142
136
  function normalizeOutputPath(outputPath, projectRoot) {
@@ -19,7 +19,7 @@ async function addLinting(host, options) {
19
19
  addPlugin: true,
20
20
  });
21
21
  tasks.push(lintTask);
22
- (0, vue_1.editEslintConfigFiles)(host, options.projectRoot, options.rootProject);
22
+ (0, vue_1.editEslintConfigFiles)(host, options.projectRoot);
23
23
  (0, devkit_1.updateJson)(host, (0, path_1.joinPathFragments)(options.projectRoot, '.eslintrc.json'), (json) => {
24
24
  const { extends: pluginExtends, ignorePatterns: pluginIgnorePatters, ...config } = json;
25
25
  return {
@@ -41,6 +41,7 @@ function createAppTsConfig(host, options) {
41
41
  compilerOptions: {
42
42
  composite: true,
43
43
  },
44
+ include: ['.nuxt/nuxt.d.ts', 'src/**/*'],
44
45
  exclude: [],
45
46
  };
46
47
  (0, devkit_1.writeJson)(host, `${options.projectRoot}/tsconfig.app.json`, json);
@@ -3,4 +3,4 @@ export declare const h3Version = "^1.8.2";
3
3
  export declare const nuxtVersion = "^3.10.0";
4
4
  export declare const nuxtDevtoolsVersion = "1.0.0";
5
5
  export declare const nuxtUiTemplatesVersion = "^1.3.1";
6
- export declare const nuxtEslintConfigVersion = "0.2.0";
6
+ export declare const nuxtEslintConfigVersion = "~0.3.6";
@@ -8,4 +8,4 @@ exports.nuxtVersion = '^3.10.0';
8
8
  exports.nuxtDevtoolsVersion = '1.0.0';
9
9
  exports.nuxtUiTemplatesVersion = '^1.3.1';
10
10
  // linting deps
11
- exports.nuxtEslintConfigVersion = '0.2.0';
11
+ exports.nuxtEslintConfigVersion = '~0.3.6';