@nx/next 17.3.0-beta.5 → 17.3.0-beta.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "17.3.0-beta.5",
3
+ "version": "17.3.0-beta.8",
4
4
  "private": false,
5
5
  "description": "The Next.js plugin for Nx contains executors and generators for managing Next.js applications and libraries within an Nx workspace. It provides:\n\n\n- Scaffolding for creating, building, serving, linting, and testing Next.js applications.\n\n- Integration with building, serving, and exporting a Next.js application.\n\n- Integration with React libraries within the workspace. \n\nWhen using Next.js in Nx, you get the out-of-the-box support for TypeScript, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "next": ">=13.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@nx/devkit": "17.3.0-beta.5",
37
+ "@nx/devkit": "17.3.0-beta.8",
38
38
  "@babel/plugin-proposal-decorators": "^7.22.7",
39
39
  "@svgr/webpack": "^8.0.1",
40
40
  "chalk": "^4.1.0",
@@ -45,12 +45,12 @@
45
45
  "url-loader": "^4.1.1",
46
46
  "tslib": "^2.3.0",
47
47
  "webpack-merge": "^5.8.0",
48
- "@nx/js": "17.3.0-beta.5",
49
- "@nx/eslint": "17.3.0-beta.5",
50
- "@nx/react": "17.3.0-beta.5",
51
- "@nx/web": "17.3.0-beta.5",
52
- "@nx/workspace": "17.3.0-beta.5",
53
- "@nrwl/next": "17.3.0-beta.5"
48
+ "@nx/js": "17.3.0-beta.8",
49
+ "@nx/eslint": "17.3.0-beta.8",
50
+ "@nx/react": "17.3.0-beta.8",
51
+ "@nx/web": "17.3.0-beta.8",
52
+ "@nx/workspace": "17.3.0-beta.8",
53
+ "@nrwl/next": "17.3.0-beta.8"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -1,43 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withNx = exports.forNextVersion = exports.getAliasForProject = exports.getNextConfig = void 0;
4
- const baseNXEnvironmentVariables = [
5
- 'NX_BASE',
6
- 'NX_CACHE_DIRECTORY',
7
- 'NX_CACHE_PROJECT_GRAPH',
8
- 'NX_DAEMON',
9
- 'NX_DEFAULT_PROJECT',
10
- 'NX_HEAD',
11
- 'NX_PERF_LOGGING',
12
- 'NX_PROFILE',
13
- 'NX_PROJECT_GRAPH_CACHE_DIRECTORY',
14
- 'NX_INVOKED_BY_RUNNER',
15
- 'NX_PROJECT_GRAPH_MAX_WORKERS',
16
- 'NX_RUNNER',
17
- 'NX_SKIP_NX_CACHE',
18
- 'NX_TASKS_RUNNER',
19
- 'NX_TASKS_RUNNER_DYNAMIC_OUTPUT',
20
- 'NX_VERBOSE_LOGGING',
21
- 'NX_DRY_RUN',
22
- 'NX_INTERACTIVE',
23
- 'NX_GENERATE_QUIET',
24
- 'NX_PREFER_TS_NODE',
25
- 'NX_TASK_TARGET_PROJECT',
26
- 'NX_TASK_TARGET_TARGET',
27
- 'NX_TASK_TARGET_CONFIGURATION',
28
- 'NX_CLI_SET',
29
- 'NX_LOAD_DOT_ENV_FILES',
30
- 'NX_WORKSPACE_ROOT',
31
- 'NX_TASK_HASH',
32
- 'NX_NEXT_DIR',
33
- 'NX_NEXT_OUTPUT_PATH',
34
- 'NX_E2E_RUN_E2E',
35
- 'NX_E2E_CI_CACHE_KEY',
36
- 'NX_MAPPINGS',
37
- 'NX_FILE_TO_RUN',
38
- 'NX_NEXT_PUBLIC_DIR',
39
- 'NX_CYPRESS_COMPONENT_TEST',
40
- ];
41
4
  function regexEqual(x, y) {
42
5
  return (x instanceof RegExp &&
43
6
  y instanceof RegExp &&
@@ -296,9 +259,6 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
296
259
  };
297
260
  }
298
261
  exports.getNextConfig = getNextConfig;
299
- function getNonBaseVariables(oldEnv) {
300
- return Object.keys(oldEnv).filter((env) => !baseNXEnvironmentVariables.includes(env));
301
- }
302
262
  function getNxEnvironmentVariables() {
303
263
  return Object.keys(process.env)
304
264
  .filter((env) => /^NX_/i.test(env))
@@ -307,7 +267,6 @@ function getNxEnvironmentVariables() {
307
267
  return env;
308
268
  }, {});
309
269
  }
310
- let hasWarnedAboutDeprecatedEnvVariables = false;
311
270
  /**
312
271
  * TODO(v18)
313
272
  * @deprecated Use Next.js 9.4+ built-in support for environment variables. Reference https://nextjs.org/docs/pages/api-reference/next-config-js/env
@@ -322,11 +281,6 @@ function addNxEnvVariables(config) {
322
281
  .map(([name, value]) => [`process.env.${name}`, `"${value}"`])
323
282
  .filter(([name]) => !maybeDefinePlugin.definitions[name])
324
283
  .forEach(([name, value]) => (maybeDefinePlugin.definitions[name] = value));
325
- const vars = getNonBaseVariables(env);
326
- if (vars.length > 0 && !hasWarnedAboutDeprecatedEnvVariables) {
327
- hasWarnedAboutDeprecatedEnvVariables = true;
328
- console.warn(`Warning, in Nx 18 environment variables starting with NX_ will not be available in the browser, and currently will not work with @nx/next:server executor.\nPlease rename the following environment variables: ${vars.join(', ')} using Next.js' built-in support for environment variables. Reference https://nextjs.org/docs/pages/api-reference/next-config-js/env`);
329
- }
330
284
  }
331
285
  }
332
286
  function getAliasForProject(node, paths) {
@@ -17,7 +17,7 @@ async function* serveExecutor(options, context) {
17
17
  }
18
18
  exports.default = serveExecutor;
19
19
  async function* runCustomServer(root, options, context) {
20
- process.env.NX_NEXT_DIR = root;
20
+ process.env.NX_NEXT_DIR ??= root;
21
21
  process.env.NX_NEXT_PUBLIC_DIR = (0, path_1.join)(root, 'public');
22
22
  const baseUrl = `http://${options.hostname || 'localhost'}:${options.port}`;
23
23
  const customServerBuild = await (0, devkit_1.runExecutor)((0, devkit_1.parseTargetString)(options.customServerTarget, context), {
@@ -8,14 +8,15 @@ const create_cli_options_1 = require("../../utils/create-cli-options");
8
8
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
9
9
  const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
10
10
  async function* serveExecutor(options, context) {
11
+ const buildOptions = (0, devkit_1.readTargetOptions)((0, devkit_1.parseTargetString)(options.buildTarget, context), context);
12
+ const projectRoot = context.workspace.projects[context.projectName].root;
13
+ // This is required for the default custom server to work. See the @nx/next:app generator.
14
+ const nextDir = (0, path_1.resolve)(context.root, buildOptions.outputPath);
15
+ process.env.NX_NEXT_DIR ??= options.dev ? projectRoot : nextDir;
11
16
  if (options.customServerTarget) {
12
17
  return yield* (0, custom_server_impl_1.default)(options, context);
13
18
  }
14
- const buildOptions = (0, devkit_1.readTargetOptions)((0, devkit_1.parseTargetString)(options.buildTarget, context), context);
15
- const projectRoot = context.workspace.projects[context.projectName].root;
16
19
  const { keepAliveTimeout, hostname } = options;
17
- // This is required for the default custom server to work. See the @nx/next:app generator.
18
- process.env.NX_NEXT_DIR = projectRoot;
19
20
  // Cast to any to overwrite NODE_ENV
20
21
  process.env.NODE_ENV = process.env.NODE_ENV
21
22
  ? process.env.NODE_ENV
@@ -29,7 +30,6 @@ async function* serveExecutor(options, context) {
29
30
  if (keepAliveTimeout && !options.dev) {
30
31
  args.push(`--keepAliveTimeout=${keepAliveTimeout}`);
31
32
  }
32
- const nextDir = (0, path_1.resolve)(context.root, buildOptions.outputPath);
33
33
  const mode = options.dev ? 'dev' : 'start';
34
34
  const turbo = options.turbo && options.dev ? '--turbo' : '';
35
35
  const experimentalHttps = options.experimentalHttps && options.dev ? '--experimental-https' : '';
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
-
3
+ <% if (src) { %>
4
+ import Index from '../src/pages/index';
5
+ <% } else { %>
4
6
  import Index from '../pages/index';
5
-
7
+ <% } %>
6
8
  describe('Index', () => {
7
9
  it('should render successfully', () => {
8
10
  const { baseElement } = render(<Index />);
@@ -25,6 +25,6 @@ export function Index() {
25
25
  <%- appContent %>
26
26
  </<%= wrapper %>>
27
27
  );
28
- };
28
+ }
29
29
 
30
30
  export default Index;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
5
6
  function addProject(host, options) {
6
7
  const targets = {};
7
8
  // Check if plugin exists in nx.json and if it doesn't then we can continue
@@ -11,6 +12,7 @@ function addProject(host, options) {
11
12
  ? p === '@nx/next/plugin'
12
13
  : p.plugin === '@nx/next/plugin');
13
14
  if (!hasPlugin) {
15
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(host, '@nx/next:build');
14
16
  targets.build = {
15
17
  executor: '@nx/next:build',
16
18
  outputs: ['{options.outputPath}'],
@@ -23,23 +23,26 @@ function createApplicationFiles(host, options) {
23
23
  pageStyleContent: `.page {}`,
24
24
  stylesExt: options.style === 'less' ? options.style : 'css',
25
25
  };
26
+ const generatedAppFilePath = options.src
27
+ ? (0, path_1.join)(options.appProjectRoot, 'src')
28
+ : options.appProjectRoot;
26
29
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/common'), options.appProjectRoot, templateVariables);
27
30
  if (options.appDir) {
28
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app'), (0, path_1.join)(options.appProjectRoot, 'app'), templateVariables);
31
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
29
32
  // RSC is not possible to unit test without extra helpers for data fetching. Leaving it to the user to figure out.
30
33
  host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'specs', `index.spec.${options.js ? 'jsx' : 'tsx'}`));
31
34
  if (options.style === 'styled-components') {
32
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-styled-components'), (0, path_1.join)(options.appProjectRoot, 'app'), templateVariables);
35
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-styled-components'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
33
36
  }
34
37
  else if (options.style === 'styled-jsx') {
35
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-styled-jsx'), (0, path_1.join)(options.appProjectRoot, 'app'), templateVariables);
38
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-styled-jsx'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
36
39
  }
37
40
  else {
38
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-default-layout'), (0, path_1.join)(options.appProjectRoot, 'app'), templateVariables);
41
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app-default-layout'), (0, path_1.join)(generatedAppFilePath, 'app'), templateVariables);
39
42
  }
40
43
  }
41
44
  else {
42
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/pages'), (0, path_1.join)(options.appProjectRoot, 'pages'), templateVariables);
45
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/pages'), (0, path_1.join)(generatedAppFilePath, 'pages'), templateVariables);
43
46
  }
44
47
  if (options.rootProject) {
45
48
  (0, devkit_1.updateJson)(host, 'tsconfig.base.json', (json) => {
@@ -83,14 +86,14 @@ function createApplicationFiles(host, options) {
83
86
  }
84
87
  if (options.styledModule) {
85
88
  if (options.appDir) {
86
- host.delete(`${options.appProjectRoot}/app/page.module.${options.style}`);
89
+ host.delete(`${generatedAppFilePath}/app/page.module.${options.style}`);
87
90
  }
88
91
  else {
89
- host.delete(`${options.appProjectRoot}/pages/${options.fileName}.module.${options.style}`);
92
+ host.delete(`${generatedAppFilePath}/pages/${options.fileName}.module.${options.style}`);
90
93
  }
91
94
  }
92
95
  if (options.style !== 'styled-components') {
93
- host.delete(`${options.appProjectRoot}/pages/_document.tsx`);
96
+ host.delete(`${generatedAppFilePath}/pages/_document.tsx`);
94
97
  }
95
98
  if (options.js) {
96
99
  host.delete(`${options.appProjectRoot}/index.d.ts`);
@@ -25,6 +25,7 @@ async function normalizeOptions(host, options) {
25
25
  : [];
26
26
  const fileName = 'index';
27
27
  const appDir = options.appDir ?? true;
28
+ const src = options.src ?? true;
28
29
  const styledModule = /^(css|scss|less)$/.test(options.style)
29
30
  ? null
30
31
  : options.style;
@@ -32,6 +33,7 @@ async function normalizeOptions(host, options) {
32
33
  return {
33
34
  ...options,
34
35
  appDir,
36
+ src,
35
37
  appProjectRoot,
36
38
  e2eProjectName,
37
39
  e2eProjectRoot,
@@ -18,5 +18,6 @@ export interface Schema {
18
18
  customServer?: boolean;
19
19
  skipPackageJson?: boolean;
20
20
  appDir?: boolean;
21
+ src?: boolean;
21
22
  rootProject?: boolean;
22
23
  }
@@ -127,6 +127,12 @@
127
127
  "description": "Enable the App Router for this project.",
128
128
  "x-prompt": "Would you like to use the App Router (recommended)?"
129
129
  },
130
+ "src": {
131
+ "type": "boolean",
132
+ "default": true,
133
+ "description": "Generate a `src` directory for the project.",
134
+ "x-prompt": "Would you like to use `src/` directory?"
135
+ },
130
136
  "rootProject": {
131
137
  "description": "Create an application at the root of the workspace.",
132
138
  "type": "boolean",
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nextInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
5
6
  const versions_1 = require("@nx/react/src/utils/versions");
7
+ const plugin_1 = require("../../plugins/plugin");
6
8
  const add_gitignore_entry_1 = require("../../utils/add-gitignore-entry");
7
9
  const versions_2 = require("../../utils/versions");
8
10
  const add_plugin_1 = require("./lib/add-plugin");
@@ -15,7 +17,7 @@ function updateDependencies(host, schema) {
15
17
  'react-dom': versions_1.reactDomVersion,
16
18
  }, {
17
19
  '@nx/next': versions_2.nxVersion,
18
- }));
20
+ }, undefined, schema.keepExistingVersions));
19
21
  return (0, devkit_1.runTasksInSerial)(...tasks);
20
22
  }
21
23
  async function nextInitGenerator(host, schema) {
@@ -27,6 +29,9 @@ async function nextInitGenerator(host, schema) {
27
29
  if (!schema.skipPackageJson) {
28
30
  installTask = updateDependencies(host, schema);
29
31
  }
32
+ if (schema.updatePackageScripts) {
33
+ await (0, update_package_scripts_1.updatePackageScripts)(host, plugin_1.createNodes);
34
+ }
30
35
  return installTask;
31
36
  }
32
37
  exports.nextInitGenerator = nextInitGenerator;
@@ -1,4 +1,6 @@
1
1
  export interface InitSchema {
2
2
  skipFormat?: boolean;
3
3
  skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ updatePackageScripts?: boolean;
4
6
  }
@@ -16,6 +16,18 @@
16
16
  "default": false,
17
17
  "description": "Do not add dependencies to `package.json`.",
18
18
  "x-priority": "internal"
19
+ },
20
+ "keepExistingVersions": {
21
+ "type": "boolean",
22
+ "x-priority": "internal",
23
+ "description": "Keep existing dependencies versions",
24
+ "default": false
25
+ },
26
+ "updatePackageScripts": {
27
+ "type": "boolean",
28
+ "x-priority": "internal",
29
+ "description": "Update `package.json` scripts with inferred targets",
30
+ "default": false
19
31
  }
20
32
  },
21
33
  "required": []