@nx/nuxt 24.0.0-pr.37405.acdaf31 → 24.0.0-rc.0

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.
@@ -0,0 +1 @@
1
+ export declare function waitForDevServer(): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForDevServer = waitForDevServer;
4
+ const dev_server_ready_check_1 = require("./src/utils/dev-server-ready-check");
5
+ async function waitForDevServer() {
6
+ await (0, dev_server_ready_check_1.waitForNuxtDevServer)();
7
+ // A config can leave handles open that would keep the check running
8
+ process.exit(0);
9
+ }
@@ -0,0 +1,2 @@
1
+ import { nxReadySignal } from './src/utils/ready-signal';
2
+ export = nxReadySignal;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const ready_signal_1 = require("./src/utils/ready-signal");
3
+ module.exports = ready_signal_1.nxReadySignal;
@@ -4,7 +4,6 @@ exports.applicationGenerator = applicationGenerator;
4
4
  exports.applicationGeneratorInternal = applicationGeneratorInternal;
5
5
  const tslib_1 = require("tslib");
6
6
  const internal_1 = require("@nx/devkit/internal");
7
- const internal_2 = require("@nx/eslint/internal");
8
7
  const devkit_1 = require("@nx/devkit");
9
8
  const init_1 = tslib_1.__importDefault(require("../init/init"));
10
9
  const normalize_options_1 = require("./lib/normalize-options");
@@ -19,7 +18,7 @@ const ensure_dependencies_1 = require("./lib/ensure-dependencies");
19
18
  const assert_supported_nuxt_version_1 = require("../../utils/assert-supported-nuxt-version");
20
19
  const prepare_project_1 = require("./lib/prepare-project");
21
20
  const node_path_1 = require("node:path");
22
- const internal_3 = require("@nx/js/internal");
21
+ const internal_2 = require("@nx/js/internal");
23
22
  async function applicationGenerator(tree, schema) {
24
23
  return await applicationGeneratorInternal(tree, {
25
24
  useProjectJson: true,
@@ -29,8 +28,7 @@ async function applicationGenerator(tree, schema) {
29
28
  async function applicationGeneratorInternal(tree, schema) {
30
29
  (0, assert_supported_nuxt_version_1.assertSupportedNuxtVersion)(tree);
31
30
  const tasks = [];
32
- const addTsPlugin = (0, internal_3.shouldConfigureTsSolutionSetup)(tree, true, // nuxt always adds plugins
33
- schema.useTsSolution);
31
+ const addTsPlugin = (0, internal_2.shouldConfigureTsSolutionSetup)(tree, schema.useTsSolution);
34
32
  const jsInitTask = await (0, js_1.initGenerator)(tree, {
35
33
  ...schema,
36
34
  tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
@@ -114,7 +112,7 @@ async function applicationGeneratorInternal(tree, schema) {
114
112
  // If we are using the new TS solution
115
113
  // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
116
114
  if (options.isUsingTsSolutionConfig) {
117
- await (0, internal_3.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
115
+ await (0, internal_2.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
118
116
  }
119
117
  tasks.push(await (0, add_linting_1.addLinting)(tree, {
120
118
  projectName: options.projectName,
@@ -122,7 +120,7 @@ async function applicationGeneratorInternal(tree, schema) {
122
120
  linter: options.linter,
123
121
  unitTestRunner: options.unitTestRunner,
124
122
  rootProject: options.rootProject,
125
- enableTypedLinting: (0, internal_2.isTypedLintingEnabled)(options),
123
+ enableTypedLinting: options.enableTypedLinting,
126
124
  }));
127
125
  if (options.unitTestRunner === 'vitest') {
128
126
  tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
@@ -140,7 +138,7 @@ async function applicationGeneratorInternal(tree, schema) {
140
138
  if (options.js)
141
139
  (0, devkit_1.toJS)(tree);
142
140
  if (options.isUsingTsSolutionConfig) {
143
- (0, internal_3.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
141
+ (0, internal_2.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
144
142
  jsx: 'preserve',
145
143
  jsxImportSource: 'vue',
146
144
  module: 'esnext',
@@ -150,7 +148,7 @@ async function applicationGeneratorInternal(tree, schema) {
150
148
  ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
151
149
  : undefined);
152
150
  }
153
- (0, internal_3.sortPackageJsonFields)(tree, options.appProjectRoot);
151
+ (0, internal_2.sortPackageJsonFields)(tree, options.appProjectRoot);
154
152
  if (!options.skipFormat)
155
153
  await (0, devkit_1.formatFiles)(tree);
156
154
  tasks.push(() => {
@@ -1,10 +1,11 @@
1
- import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
1
+ import tsconfigPaths from 'vite-tsconfig-paths';
2
2
  import { defineNuxtConfig } from 'nuxt/config';
3
3
 
4
4
  // https://nuxt.com/docs/api/configuration/nuxt-config
5
5
  export default defineNuxtConfig({
6
6
  workspaceDir: '<%= offsetFromRoot %>',
7
7
  devtools: { enabled: true },
8
+ modules: ['@nx/nuxt/ready-signal'],
8
9
  devServer: {
9
10
  host: 'localhost',
10
11
  port: 4200,
@@ -22,8 +23,6 @@ export default defineNuxtConfig({
22
23
  css: ['~/assets/css/styles.<%= style %>'],
23
24
  <%_ } _%>
24
25
  vite: {
25
- plugins: [
26
- nxViteTsPaths()
27
- ],
26
+ plugins: [tsconfigPaths({ loose: true })],
28
27
  },
29
28
  });
@@ -1,4 +1,4 @@
1
- import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
1
+ import tsconfigPaths from 'vite-tsconfig-paths';
2
2
  import { defineNuxtConfig } from 'nuxt/config';
3
3
 
4
4
  // https://nuxt.com/docs/api/configuration/nuxt-config
@@ -6,6 +6,7 @@ export default defineNuxtConfig({
6
6
  workspaceDir: '<%= offsetFromRoot %>',
7
7
  srcDir: 'src',
8
8
  devtools: { enabled: true },
9
+ modules: ['@nx/nuxt/ready-signal'],
9
10
  devServer: {
10
11
  host: 'localhost',
11
12
  port: 4200,
@@ -23,8 +24,6 @@ export default defineNuxtConfig({
23
24
  css: ['~/assets/css/styles.<%= style %>'],
24
25
  <%_ } _%>
25
26
  vite: {
26
- plugins: [
27
- nxViteTsPaths()
28
- ],
27
+ plugins: [tsconfigPaths({ loose: true })],
29
28
  },
30
29
  });
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addE2e = addE2e;
4
4
  const internal_1 = require("@nx/devkit/internal");
5
- const internal_2 = require("@nx/eslint/internal");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const versions_1 = require("../../../utils/versions");
8
7
  async function addE2e(host, options) {
@@ -46,7 +45,6 @@ async function addE2e(host, options) {
46
45
  baseUrl: e2eWebServerInfo.e2eWebServerAddress,
47
46
  ciBaseUrl: e2eWebServerInfo.e2eCiBaseUrl,
48
47
  jsx: true,
49
- addPlugin: true,
50
48
  });
51
49
  return e2eTask;
52
50
  }
@@ -81,10 +79,11 @@ async function addE2e(host, options) {
81
79
  directory: 'src',
82
80
  js: false,
83
81
  linter: options.linter,
84
- enableTypedLinting: (0, internal_2.isTypedLintingEnabled)(options),
85
- webServerAddress: e2eWebServerInfo.e2eCiBaseUrl,
86
- webServerCommand: e2eWebServerInfo.e2eCiWebServerCommand,
87
- addPlugin: true,
82
+ enableTypedLinting: options.enableTypedLinting,
83
+ webServerCommand: e2eWebServerInfo.e2eWebServerCommand,
84
+ webServerAddress: e2eWebServerInfo.e2eWebServerAddress,
85
+ ciWebServerCommand: e2eWebServerInfo.e2eCiWebServerCommand,
86
+ ciWebServerAddress: e2eWebServerInfo.e2eCiBaseUrl,
88
87
  });
89
88
  return e2eTask;
90
89
  }
@@ -108,5 +107,5 @@ async function getNuxtE2EWebServerInfo(tree, projectName, configFilePath) {
108
107
  defaultE2EWebServerAddress: `http://localhost:${e2ePort}`,
109
108
  defaultE2ECiBaseUrl: 'http://localhost:4200',
110
109
  defaultE2EPort: e2ePort,
111
- }, true);
110
+ });
112
111
  }
@@ -21,7 +21,6 @@ async function addVitest(tree, options) {
21
21
  skipFormat: true,
22
22
  testEnvironment: 'jsdom',
23
23
  skipViteConfig: true,
24
- addPlugin: true,
25
24
  }, hasPlugin);
26
25
  createOrEditViteConfig(tree, {
27
26
  project: options.projectName,
@@ -9,7 +9,8 @@ const version_utils_1 = require("../../../utils/version-utils");
9
9
  async function ensureDependencies(host, options) {
10
10
  const nuxtVersions = await (0, version_utils_1.getNuxtDependenciesVersionsToInstall)(host);
11
11
  const devDependencies = {
12
- '@nx/vite': versions_1.nxVersion, // needed for the nxViteTsPaths plugin and @nx/vite/plugin
12
+ 'vite-tsconfig-paths': '~4.3.2',
13
+ '@nx/vite': versions_1.nxVersion, // needed for @nx/vite/plugin
13
14
  '@nuxt/devtools': nuxtVersions.nuxtDevtools,
14
15
  '@nuxt/kit': nuxtVersions.nuxtKit,
15
16
  '@nuxt/schema': nuxtVersions.nuxtSchema,
@@ -13,10 +13,6 @@ export interface Schema {
13
13
  skipPackageJson?: boolean;
14
14
  rootProject?: boolean;
15
15
  enableTypedLinting?: boolean;
16
- /**
17
- * @deprecated Use `enableTypedLinting` instead. This option will be removed in Nx v24.
18
- */
19
- setParserOptionsProject?: boolean;
20
16
  style?: 'css' | 'scss' | 'none';
21
17
  nxCloudToken?: string;
22
18
  useTsSolution?: boolean;
@@ -107,12 +107,6 @@
107
107
  "description": "Whether to enable typed linting. For flat configs, this configures the recommended `parserOptions.projectService` and `tsconfigRootDir`. For legacy `.eslintrc` configs, this configures `parserOptions.project`. We do not enable this by default for lint performance reasons.",
108
108
  "default": false
109
109
  },
110
- "setParserOptionsProject": {
111
- "type": "boolean",
112
- "description": "Deprecated alias for `enableTypedLinting`.",
113
- "default": false,
114
- "x-deprecated": "Use `enableTypedLinting` instead. This option will be removed in Nx v24."
115
- },
116
110
  "useProjectJson": {
117
111
  "type": "boolean",
118
112
  "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
@@ -17,10 +17,7 @@ async function storybookConfigurationGenerator(tree, options) {
17
17
  : sourceRoot?.endsWith('/src')
18
18
  ? 'src'
19
19
  : 'src'; // default to src for backward compatibility
20
- const storybookConfigurationGenerator = await (0, vue_1.storybookConfigurationGenerator)(tree, {
21
- ...options,
22
- addPlugin: true,
23
- });
20
+ const storybookConfigurationGenerator = await (0, vue_1.storybookConfigurationGenerator)(tree, options);
24
21
  // Default tsConfiguration to true to match schema default
25
22
  const tsConfiguration = options.tsConfiguration ?? true;
26
23
  // Write the preview file after the base storybook configuration is set up
@@ -7,6 +7,7 @@ const js_1 = require("@nx/js");
7
7
  const path_1 = require("path");
8
8
  const fs_1 = require("fs");
9
9
  const executor_utils_1 = require("../utils/executor-utils");
10
+ const ready_signal_1 = require("../utils/ready-signal");
10
11
  const internal_2 = require("@nx/js/internal");
11
12
  const cachePath = (0, path_1.join)(internal_1.workspaceDataDirectory, 'nuxt.hash');
12
13
  const targetsCache = new internal_1.PluginCache(cachePath);
@@ -66,7 +67,7 @@ async function buildNuxtTargets(configFilePath, projectRoot, options, context, p
66
67
  const namedInputs = (0, internal_1.getNamedInputs)(projectRoot, context);
67
68
  const targets = {};
68
69
  targets[options.buildTargetName] = buildTarget(options.buildTargetName, namedInputs, buildOutputs, projectRoot);
69
- targets[options.serveTargetName] = serveTarget(projectRoot, namedInputs);
70
+ targets[options.serveTargetName] = serveTarget(projectRoot, namedInputs, nuxtConfig.signalsReady);
70
71
  targets[options.serveStaticTargetName] = serveStaticTarget(options, namedInputs);
71
72
  targets[options.buildStaticTargetName] = buildStaticTarget(options.buildStaticTargetName, namedInputs, buildOutputs, projectRoot);
72
73
  (0, internal_2.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
@@ -92,13 +93,16 @@ function buildInputs(namedInputs) {
92
93
  },
93
94
  ];
94
95
  }
95
- function serveTarget(projectRoot, namedInputs) {
96
+ function serveTarget(projectRoot, namedInputs, signalsReady) {
96
97
  const targetConfig = {
97
98
  command: `nuxt dev`,
98
99
  options: {
99
100
  cwd: projectRoot,
100
101
  },
101
102
  continuous: true,
103
+ readyWhen: signalsReady
104
+ ? { signal: true }
105
+ : (0, internal_1.getReadyCheckReadyWhen)('@nx/nuxt/ready-check'),
102
106
  inputs: buildInputs(namedInputs),
103
107
  };
104
108
  return targetConfig;
@@ -107,6 +111,7 @@ function serveStaticTarget(options, namedInputs) {
107
111
  const targetConfig = {
108
112
  dependsOn: [`${options.buildStaticTargetName}`],
109
113
  continuous: true,
114
+ readyWhen: { signal: true },
110
115
  inputs: buildInputs(namedInputs),
111
116
  executor: '@nx/web:file-server',
112
117
  options: {
@@ -138,10 +143,10 @@ function buildStaticTarget(buildStaticTargetName, namedInputs, buildOutputs, pro
138
143
  return targetConfig;
139
144
  }
140
145
  async function getInfoFromNuxtConfig(configFilePath, context, projectRoot) {
141
- // Only `buildDir` is read below. Typing it to the full `@nuxt/schema`
142
- // `NuxtOptions` couples to one schema version, which clashes when
143
- // `loadNuxtConfig` returns the (possibly older) `@nuxt/schema` bundled by the
144
- // installed `@nuxt/kit`. Type just what we read so it holds across the
146
+ // Only `buildDir` and `modules` are read below. Typing it to the full
147
+ // `@nuxt/schema` `NuxtOptions` couples to one schema version, which clashes
148
+ // when `loadNuxtConfig` returns the (possibly older) `@nuxt/schema` bundled by
149
+ // the installed `@nuxt/kit`. Type just what we read so it holds across the
145
150
  // supported Nuxt 3.x–4.x range.
146
151
  let config;
147
152
  if (process.env.NX_ISOLATE_PLUGINS !== 'false') {
@@ -157,6 +162,7 @@ async function getInfoFromNuxtConfig(configFilePath, context, projectRoot) {
157
162
  // Match .nuxt default build dir from '@nuxt/schema'
158
163
  // See: https://github.com/nuxt/nuxt/blob/871404ae5673425aeedde82f123ea58aa7c6facf/packages/schema/src/config/common.ts#L117-L119
159
164
  '.nuxt',
165
+ signalsReady: (0, ready_signal_1.loadsReadySignalModule)(config?.modules),
160
166
  };
161
167
  }
162
168
  function getOutputs(nuxtConfig, projectRoot) {
@@ -7,8 +7,4 @@ export declare function addLinting(host: Tree, options: {
7
7
  unitTestRunner?: 'vitest' | 'none';
8
8
  rootProject?: boolean;
9
9
  enableTypedLinting?: boolean;
10
- /**
11
- * @deprecated Use `enableTypedLinting` instead. This option will be removed in Nx v24.
12
- */
13
- setParserOptionsProject?: boolean;
14
10
  }): Promise<GeneratorCallback>;
@@ -14,13 +14,12 @@ async function addLinting(host, options) {
14
14
  tsConfigPaths: [(0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json')],
15
15
  unitTestRunner: options.unitTestRunner,
16
16
  rootProject: options.rootProject,
17
- enableTypedLinting: (0, internal_1.isTypedLintingEnabled)(options),
18
- addPlugin: true,
17
+ enableTypedLinting: options.enableTypedLinting,
19
18
  }));
20
19
  // Everything below configures ESLint — predefined configs, `extends`, ignore
21
20
  // entries — which have no equivalent in other linters.
22
21
  if (options.linter === 'eslint') {
23
- const enableTypedLinting = (0, internal_1.isTypedLintingEnabled)(options);
22
+ const { enableTypedLinting } = options;
24
23
  const isFlatConfig = (0, internal_1.useFlatConfig)(host);
25
24
  // Version-aware dependencies:
26
25
  // - Flat config (v4+): use @nuxt/eslint-config ^1.10.0 with createConfigForNuxt
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The readyWhen of the inferred serve target when the config doesn't load the
3
+ * ready-signal module. Runs in the env and with the options of the task,
4
+ * resolves the address the way `nuxt dev` does, and waits until it serves the
5
+ * app there.
6
+ */
7
+ export declare function waitForNuxtDevServer(): Promise<void>;
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForNuxtDevServer = waitForNuxtDevServer;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const internal_1 = require("@nx/devkit/internal");
6
+ const fs_1 = require("fs");
7
+ const path_1 = require("path");
8
+ const semver_1 = require("semver");
9
+ const util_1 = require("util");
10
+ const executor_utils_1 = require("./executor-utils");
11
+ const wait_until_serving_1 = require("./wait-until-serving");
12
+ // The first version of each range of `nuxt dev` CLIs, nuxi or @nuxt/cli, that
13
+ // load the config and resolve the address they listen on alike, latest first
14
+ const CLI_RANGES = [
15
+ '4.0.0',
16
+ '3.31.0',
17
+ '3.30.0',
18
+ '3.26.0',
19
+ '3.25.0',
20
+ '3.15.0',
21
+ '3.8.4',
22
+ '3.7.2',
23
+ '3.7.1',
24
+ '3.7.0',
25
+ '3.6.2',
26
+ '3.2.1',
27
+ '3.1.1',
28
+ '3.0.0',
29
+ ];
30
+ // The `nuxt dev` options that take a value, with the aliases citty gives them
31
+ const VALUE_OPTIONS = {
32
+ cwd: [],
33
+ dotenv: [],
34
+ profile: [],
35
+ logLevel: ['log-level'],
36
+ envName: ['env-name'],
37
+ extends: ['e'],
38
+ port: ['p'],
39
+ host: ['h'],
40
+ publicURL: ['public-url'],
41
+ sslCert: ['ssl-cert'],
42
+ sslKey: ['ssl-key'],
43
+ 'https.cert': ['httpsCert', 'https-cert'],
44
+ 'https.key': ['httpsKey', 'https-key'],
45
+ 'https.pfx': ['httpsPfx', 'https-pfx'],
46
+ 'https.passphrase': ['httpsPassphrase', 'https-passphrase'],
47
+ 'https.validityDays': ['httpsValidityDays', 'https-validity-days'],
48
+ 'https.domains': ['httpsDomains', 'https-domains'],
49
+ };
50
+ const CLI_4_VALUE_OPTIONS = {
51
+ ...VALUE_OPTIONS,
52
+ 'open.url': ['openUrl', 'open-url'],
53
+ };
54
+ // The options @nuxt/cli 4 takes more than once
55
+ const CLI_4_MULTIPLE = ['dotenv', 'extends'];
56
+ /**
57
+ * The args `nuxt dev` gets from the task's options, as the citty parser of
58
+ * its CLI reads them.
59
+ */
60
+ function parseNuxtDevArgs(options, cli) {
61
+ const cli4 = cli === '4.0.0';
62
+ const valueOptions = {
63
+ ...(cli4 ? CLI_4_VALUE_OPTIONS : VALUE_OPTIONS),
64
+ // nuxi 3.7.0 and 3.7.1 give `port` no `-p` alias, and never read `-p`
65
+ ...(cli === '3.7.0' || cli === '3.7.1' ? { port: [], p: [] } : {}),
66
+ };
67
+ // As citty passes them to `util.parseArgs`, which reads any other option as
68
+ // a flag
69
+ const parseOptions = Object.fromEntries(Object.entries(valueOptions).flatMap(([name, aliases]) => {
70
+ const short = [name, ...aliases].find((alias) => alias.length === 1);
71
+ const multiple = cli4 && CLI_4_MULTIPLE.includes(name);
72
+ return [
73
+ [name, { type: 'string', multiple, ...(short && { short }) }],
74
+ ...aliases.map((alias) => [alias, { type: 'string' }]),
75
+ ];
76
+ }));
77
+ const { values, positionals } = (0, util_1.parseArgs)({
78
+ args: (0, internal_1.getForwardedArgs)(options),
79
+ options: parseOptions,
80
+ allowPositionals: true,
81
+ strict: false,
82
+ });
83
+ // The values of an option, where one given no value is `true`
84
+ const read = (name) => {
85
+ for (const n of [name, ...valueOptions[name]]) {
86
+ const value = values[n];
87
+ if (value !== undefined)
88
+ return [value].flat();
89
+ }
90
+ };
91
+ // citty makes `true` '' for an option it types as a string
92
+ const readStrings = (name) => read(name)?.map((value) => (value === true ? '' : String(value)));
93
+ const readString = (name) => readStrings(name)?.at(-1);
94
+ return {
95
+ port: readString('port'),
96
+ // Typed as a string from @nuxt/cli 4
97
+ host: !cli4 && read('host')?.at(-1) === true ? true : readString('host'),
98
+ cwd: readString('cwd'),
99
+ rootDir: positionals[0],
100
+ dotenv: cli4 ? readStrings('dotenv') : readString('dotenv'),
101
+ envName: readString('envName'),
102
+ extends: cli4 ? readStrings('extends') : readString('extends'),
103
+ };
104
+ }
105
+ /**
106
+ * The readyWhen of the inferred serve target when the config doesn't load the
107
+ * ready-signal module. Runs in the env and with the options of the task,
108
+ * resolves the address the way `nuxt dev` does, and waits until it serves the
109
+ * app there.
110
+ */
111
+ async function waitForNuxtDevServer() {
112
+ await (0, internal_1.runReadyCheck)(async ({ options, root }) => {
113
+ const cli = getCliRange(root);
114
+ const args = parseNuxtDevArgs(options, cli);
115
+ const envBeforeDotenv = { ...process.env };
116
+ // `nuxt dev` forces it, and c12 reads it as the default --envName
117
+ process.env.NODE_ENV = 'development';
118
+ // --cwd from nuxi 3.7, --envName from 3.15 and --extends from 3.26
119
+ const cwd = (0, path_1.resolve)(((0, semver_1.gte)(cli, '3.7.0') && args.cwd) || args.rootDir || '.');
120
+ const { loadNuxtConfig } = await (0, executor_utils_1.loadNuxtKitDynamicImport)();
121
+ const nuxtOptions = await loadNuxtConfig({
122
+ cwd,
123
+ envName: (0, semver_1.gte)(cli, '3.15.0') ? args.envName : undefined,
124
+ dotenv: { cwd, fileName: args.dotenv },
125
+ overrides: {
126
+ dev: true,
127
+ extends: (0, semver_1.gte)(cli, '3.26.0') ? args.extends : undefined,
128
+ },
129
+ });
130
+ const address = getListenAddress(cli, args, envBeforeDotenv, nuxtOptions);
131
+ if (address) {
132
+ await (0, wait_until_serving_1.waitUntilServing)(getServerUrls(address));
133
+ }
134
+ // Waited for above, as `nuxt dev` takes the port before it serves the app
135
+ return null;
136
+ });
137
+ }
138
+ // The CLI `nuxt dev` runs: the one the nearest node_modules/.bin/nuxt links
139
+ // to, else nuxt's own: nuxi before Nuxt 3.15.2, and @nuxt/cli from it
140
+ function getCliRange(root) {
141
+ let cliVersion = getLinkedCliVersion(root);
142
+ if (cliVersion === undefined) {
143
+ let nuxt;
144
+ try {
145
+ nuxt = (0, internal_1.readModulePackageJson)('nuxt', [root]);
146
+ }
147
+ catch {
148
+ // Nothing to match, so match the CLI a new project gets
149
+ return '4.0.0';
150
+ }
151
+ const cli = nuxt.packageJson.dependencies?.nuxi ? 'nuxi' : '@nuxt/cli';
152
+ cliVersion = (0, internal_1.getInstalledPackageVersion)(cli, [(0, path_1.dirname)(nuxt.path)]);
153
+ }
154
+ const version = (0, semver_1.valid)(cliVersion);
155
+ // Without a 3.x or later version to match, resolve as the latest 3.x CLIs do
156
+ return ((version && CLI_RANGES.find((start) => (0, semver_1.gte)(version, start))) || '3.31.0');
157
+ }
158
+ // The version of the nuxi or @nuxt/cli that the first node_modules/.bin/nuxt
159
+ // from `root` up links to, as run-commands puts those dirs first on the PATH
160
+ function getLinkedCliVersion(root) {
161
+ for (let dir = root;; dir = (0, path_1.dirname)(dir)) {
162
+ const bin = (0, path_1.join)(dir, 'node_modules', '.bin', 'nuxt');
163
+ if ((0, fs_1.existsSync)(bin)) {
164
+ if (!(0, fs_1.lstatSync)(bin).isSymbolicLink())
165
+ return undefined;
166
+ let packageRoot = (0, path_1.dirname)((0, fs_1.realpathSync)(bin));
167
+ while (!(0, fs_1.existsSync)((0, path_1.join)(packageRoot, 'package.json'))) {
168
+ if ((0, path_1.dirname)(packageRoot) === packageRoot)
169
+ return undefined;
170
+ packageRoot = (0, path_1.dirname)(packageRoot);
171
+ }
172
+ const { name, version } = (0, devkit_1.readJsonFile)((0, path_1.join)(packageRoot, 'package.json'));
173
+ return name === 'nuxi' || name === '@nuxt/cli' ? version : undefined;
174
+ }
175
+ if ((0, path_1.dirname)(dir) === dir)
176
+ return undefined;
177
+ }
178
+ }
179
+ // The CLIs before 3.30 read the env once they have loaded .env, which loading
180
+ // the config does here too
181
+ function getListenAddress(cli, args, envBeforeDotenv, nuxtOptions) {
182
+ const env = process.env;
183
+ const config = nuxtOptions.devServer;
184
+ // The root config as written, without its layers or the schema defaults
185
+ const rootLayer = nuxtOptions._layers?.[0]?.config;
186
+ // get-port-please skips a PORT that isn't a number
187
+ const envPort = Number.parseInt(env.PORT ?? '') || undefined;
188
+ switch (cli) {
189
+ case '3.0.0':
190
+ return (0, internal_1.getServerAddress)(
191
+ // get-port-please takes PORT over the port nuxi passes it
192
+ envPort || args.port || env.NUXT_PORT || 3000, args.host || env.NUXT_HOST || env.HOST);
193
+ case '3.1.1':
194
+ return (0, internal_1.getServerAddress)(args.port || env.NUXT_PORT || envPort || 3000, args.host || env.NUXT_HOST || env.HOST);
195
+ case '3.2.1':
196
+ return (0, internal_1.getServerAddress)(args.port || env.NUXT_PORT || config.port, args.host || env.NUXT_HOST || config.host);
197
+ case '3.6.2':
198
+ return (0, internal_1.getServerAddress)(args.port || env.NUXT_PORT || env.NITRO_PORT || config.port, args.host || env.NUXT_HOST || env.NITRO_HOST || config.host);
199
+ case '3.7.0':
200
+ return (0, internal_1.getServerAddress)(args.port || env.NUXT_PORT || env.NITRO_PORT || env.PORT || config.port,
201
+ // Its listhen reads the --host arg, not the host nuxi resolves
202
+ args.host ?? env.HOST);
203
+ case '3.7.1':
204
+ case '3.7.2': {
205
+ // Without a root layer, they read the resolved config
206
+ const { port, host } = (rootLayer ?? nuxtOptions).devServer ?? {};
207
+ return (0, internal_1.getServerAddress)(args.port ??
208
+ env.NUXT_PORT ??
209
+ env.NITRO_PORT ??
210
+ env.PORT ??
211
+ port ??
212
+ // get-port-please's own default
213
+ 3000, args.host ?? env.NUXT_HOST ?? env.NITRO_HOST ?? env.HOST ?? host);
214
+ }
215
+ case '3.8.4':
216
+ case '3.15.0':
217
+ return (0, internal_1.getServerAddress)(args.port ?? env.NUXT_PORT ?? env.NITRO_PORT ?? env.PORT ?? config.port, args.host ??
218
+ env.NUXT_HOST ??
219
+ env.NITRO_HOST ??
220
+ env.HOST ??
221
+ rootLayer?.devServer?.host);
222
+ case '3.25.0':
223
+ case '3.26.0':
224
+ return (0, internal_1.getServerAddress)(args.port ?? env.NUXT_PORT ?? env.NITRO_PORT ?? env.PORT ?? config.port, args.host ?? env.NUXT_HOST ?? env.NITRO_HOST ?? env.HOST ?? config.host);
225
+ case '3.30.0':
226
+ if (envBeforeDotenv._PORT) {
227
+ return (0, internal_1.getServerAddress)(envBeforeDotenv._PORT, '127.0.0.1');
228
+ }
229
+ return (0, internal_1.getServerAddress)(args.port ?? config.port, args.host ?? config.host);
230
+ case '3.31.0': {
231
+ const { _PORT, NUXT_PORT, NITRO_PORT, PORT, NUXT_HOST, NITRO_HOST, HOST, } = envBeforeDotenv;
232
+ if (_PORT) {
233
+ return (0, internal_1.getServerAddress)(_PORT, '127.0.0.1');
234
+ }
235
+ return (0, internal_1.getServerAddress)((args.port || NUXT_PORT || NITRO_PORT || PORT) ?? config.port, (args.host || NUXT_HOST || NITRO_HOST || HOST) ?? config.host);
236
+ }
237
+ case '4.0.0': {
238
+ const { NUXT_PORT, NITRO_PORT, PORT, NUXT_HOST, NITRO_HOST, HOST } = envBeforeDotenv;
239
+ return (0, internal_1.getServerAddress)(args.port || NUXT_PORT || NITRO_PORT || PORT || config.port, args.host ?? (NUXT_HOST || NITRO_HOST || HOST) ?? config.host);
240
+ }
241
+ default: {
242
+ const unhandled = cli;
243
+ throw new Error(`Unhandled \`nuxt dev\` CLI range: ${unhandled}`);
244
+ }
245
+ }
246
+ }
247
+ // In both schemes, since the wrong one gets no answer, and on both loopback
248
+ // addresses when the host is a wildcard or localhost
249
+ function getServerUrls({ port, host }) {
250
+ return (host ? [host] : ['127.0.0.1', '::1']).flatMap((h) => {
251
+ const authority = `${h.includes(':') ? `[${h}]` : h}:${port}`;
252
+ return [`http://${authority}/`, `https://${authority}/`];
253
+ });
254
+ }
@@ -0,0 +1,21 @@
1
+ import type { AddressInfo } from 'net';
2
+ interface Server {
3
+ address(): AddressInfo | string | null;
4
+ }
5
+ interface Listener {
6
+ url?: string;
7
+ https?: unknown;
8
+ }
9
+ interface NuxtWithHooks {
10
+ hook(name: 'listen', fn: (server: Server, listener: Listener) => void): unknown;
11
+ hook(name: 'build:done', fn: () => void): unknown;
12
+ }
13
+ /**
14
+ * Nuxt module that reports the `nuxt dev` server's URL to an Nx task whose
15
+ * readyWhen is `signal`, once it has built and serves the app. Does nothing
16
+ * outside such a task.
17
+ */
18
+ export declare function nxReadySignal(_options: unknown, nuxt: NuxtWithHooks): void;
19
+ /** Whether a Nuxt config's `modules` load {@link nxReadySignal}. */
20
+ export declare function loadsReadySignalModule(modules: unknown): boolean;
21
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nxReadySignal = nxReadySignal;
4
+ exports.loadsReadySignalModule = loadsReadySignalModule;
5
+ const wait_until_serving_1 = require("./wait-until-serving");
6
+ // Set on the module so inference can find it in a config it has loaded
7
+ const READY_SIGNAL_MODULE = Symbol.for('@nx/ready-signal-plugin');
8
+ /**
9
+ * Nuxt module that reports the `nuxt dev` server's URL to an Nx task whose
10
+ * readyWhen is `signal`, once it has built and serves the app. Does nothing
11
+ * outside such a task.
12
+ */
13
+ function nxReadySignal(_options, nuxt) {
14
+ if (!process.env.NX_READY_SIGNAL_SOCKET) {
15
+ return;
16
+ }
17
+ const { emitReadySignal } = require('@nx/devkit');
18
+ const { getListeningUrl } = require('@nx/devkit/internal');
19
+ nuxt.hook('listen', (server, listener) => {
20
+ // Added after setup, this runs after the build:done hooks setup added,
21
+ // such as Nitro's wait to compile
22
+ nuxt.hook('build:done', () => {
23
+ const url = getCliUrl(listener) ??
24
+ getListeningUrl(server.address(), !!listener.https);
25
+ if (!url) {
26
+ // A server on a socket can't be probed
27
+ emitReadySignal();
28
+ return;
29
+ }
30
+ // nuxi 3.7.0 to 3.7.2 pass `{}` from a forked child, whose server is
31
+ // internal, so its address isn't the one to report
32
+ const internal = Object.keys(listener).length === 0;
33
+ // The CLI serves the app only after this hook returns: until then it
34
+ // answers 503 or holds the request, so the hook must not wait for it
35
+ void (0, wait_until_serving_1.waitUntilServing)([url]).then(() => internal ? emitReadySignal() : emitReadySignal(url));
36
+ });
37
+ });
38
+ }
39
+ nxReadySignal[READY_SIGNAL_MODULE] = true;
40
+ // The URL the CLI serves on, which is its proxy's when Nuxt runs behind one.
41
+ // A wildcard host maps to localhost, as `getListeningUrl` maps it.
42
+ function getCliUrl({ url }) {
43
+ if (!url || !URL.canParse(url)) {
44
+ return undefined;
45
+ }
46
+ const parsed = new URL(url);
47
+ if (parsed.hostname === '0.0.0.0' || parsed.hostname === '[::]') {
48
+ parsed.hostname = 'localhost';
49
+ }
50
+ return parsed.href;
51
+ }
52
+ /** Whether a Nuxt config's `modules` load {@link nxReadySignal}. */
53
+ function loadsReadySignalModule(modules) {
54
+ return (Array.isArray(modules) &&
55
+ modules.some((entry) => {
56
+ const module = Array.isArray(entry) ? entry[0] : entry;
57
+ return (module === '@nx/nuxt/ready-signal' || !!module?.[READY_SIGNAL_MODULE]);
58
+ }));
59
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Resolves once one of `urls` answers with any status but 503, which `nuxt dev`
3
+ * answers until it serves the app. Retries the URLs that refuse or fail.
4
+ */
5
+ export declare function waitUntilServing(urls: string[]): Promise<void>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitUntilServing = waitUntilServing;
4
+ const http_1 = require("http");
5
+ const https_1 = require("https");
6
+ /**
7
+ * Resolves once one of `urls` answers with any status but 503, which `nuxt dev`
8
+ * answers until it serves the app. Retries the URLs that refuse or fail.
9
+ */
10
+ async function waitUntilServing(urls) {
11
+ const controller = new AbortController();
12
+ try {
13
+ await Promise.any(urls.map((url) => poll(url, controller.signal)));
14
+ }
15
+ finally {
16
+ controller.abort();
17
+ }
18
+ }
19
+ async function poll(url, signal) {
20
+ for (;;) {
21
+ const status = await getStatus(url, signal);
22
+ signal.throwIfAborted();
23
+ if (status !== undefined && status !== 503) {
24
+ return;
25
+ }
26
+ await new Promise((resolve) => setTimeout(resolve, 250));
27
+ }
28
+ }
29
+ // No timeout: the CLIs that hold a request until they serve the app answer
30
+ // it after the build
31
+ function getStatus(url, signal) {
32
+ return new Promise((resolve) => {
33
+ const onResponse = (response) => {
34
+ response.resume();
35
+ resolve(response.statusCode);
36
+ };
37
+ const request = url.startsWith('https:')
38
+ ? // Only the status is read, and dev certificates are self-signed
39
+ (0, https_1.request)(url, { agent: false, rejectUnauthorized: false, signal }, onResponse)
40
+ : (0, http_1.request)(url, { agent: false, signal }, onResponse);
41
+ request.on('error', () => resolve(undefined)).end();
42
+ });
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/nuxt",
3
- "version": "24.0.0-pr.37405.acdaf31",
3
+ "version": "24.0.0-rc.0",
4
4
  "private": false,
5
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": {
@@ -28,6 +28,12 @@
28
28
  "*": {
29
29
  "plugin": [
30
30
  "dist/plugin.d.ts"
31
+ ],
32
+ "ready-signal": [
33
+ "dist/ready-signal.d.ts"
34
+ ],
35
+ "ready-check": [
36
+ "dist/ready-check.d.ts"
31
37
  ]
32
38
  }
33
39
  },
@@ -51,6 +57,16 @@
51
57
  "@nx/nx-source": "./plugin.ts",
52
58
  "types": "./dist/plugin.d.ts",
53
59
  "default": "./dist/plugin.js"
60
+ },
61
+ "./ready-signal": {
62
+ "@nx/nx-source": "./ready-signal.ts",
63
+ "types": "./dist/ready-signal.d.ts",
64
+ "default": "./dist/ready-signal.js"
65
+ },
66
+ "./ready-check": {
67
+ "@nx/nx-source": "./ready-check.ts",
68
+ "types": "./dist/ready-check.d.ts",
69
+ "default": "./dist/ready-check.js"
54
70
  }
55
71
  },
56
72
  "nx-migrations": {
@@ -59,24 +75,24 @@
59
75
  },
60
76
  "dependencies": {
61
77
  "tslib": "^2.3.0",
62
- "@nx/devkit": "24.0.0-pr.37405.acdaf31",
63
- "@nx/js": "24.0.0-pr.37405.acdaf31",
64
- "@nx/eslint": "24.0.0-pr.37405.acdaf31",
65
- "@nx/vue": "24.0.0-pr.37405.acdaf31",
66
- "@nx/vite": "24.0.0-pr.37405.acdaf31",
67
- "@nx/vitest": "24.0.0-pr.37405.acdaf31",
78
+ "@nx/devkit": "24.0.0-rc.0",
79
+ "@nx/js": "24.0.0-rc.0",
80
+ "@nx/eslint": "24.0.0-rc.0",
81
+ "@nx/vue": "24.0.0-rc.0",
82
+ "@nx/vite": "24.0.0-rc.0",
83
+ "@nx/vitest": "24.0.0-rc.0",
68
84
  "semver": "^7.6.3"
69
85
  },
70
86
  "devDependencies": {
71
87
  "nuxt": "^3.21.10",
72
- "nx": "24.0.0-pr.37405.acdaf31"
88
+ "nx": "24.0.0-rc.0"
73
89
  },
74
90
  "peerDependencies": {
75
91
  "nuxt": ">=3.0.0 <5.0.0",
76
92
  "@nuxt/schema": "^3.0.0 || ^4.0.0",
77
93
  "@nuxt/kit": "^3.0.0 || ^4.0.0",
78
- "@nx/cypress": "24.0.0-pr.37405.acdaf31",
79
- "@nx/playwright": "24.0.0-pr.37405.acdaf31"
94
+ "@nx/cypress": "24.0.0-rc.0",
95
+ "@nx/playwright": "24.0.0-rc.0"
80
96
  },
81
97
  "peerDependenciesMeta": {
82
98
  "nuxt": {