@nx/next 17.0.4 → 17.0.6

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.
Files changed (73) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +2 -2
  4. package/migrations.json +0 -24
  5. package/package.json +10 -12
  6. package/plugins/component-testing.d.ts +11 -1
  7. package/plugins/component-testing.js +10 -26
  8. package/plugins/with-nx.d.ts +1 -1
  9. package/plugins/with-nx.js +86 -68
  10. package/plugins/with-stylus.js +1 -1
  11. package/src/executors/build/build.impl.js +9 -20
  12. package/src/executors/build/lib/create-next-config-file.js +2 -5
  13. package/src/executors/build/lib/test-fixtures/ensure-exts/baz.json +0 -1
  14. package/src/executors/build/lib/update-package-json.js +1 -10
  15. package/src/executors/build/schema.json +1 -1
  16. package/src/executors/export/export.impl.js +9 -9
  17. package/src/executors/server/custom-server.impl.js +2 -3
  18. package/src/executors/server/schema.json +0 -4
  19. package/src/executors/server/server.impl.js +11 -13
  20. package/src/generators/application/application.js +0 -24
  21. package/src/generators/application/files/app/page.tsx__tmpl__ +1 -1
  22. package/src/generators/application/files/common/specs/__fileName__.spec.tsx__tmpl__ +3 -10
  23. package/src/generators/application/files/common/tsconfig.json__tmpl__ +5 -5
  24. package/src/generators/application/files/pages/__fileName__.tsx__tmpl__ +1 -1
  25. package/src/generators/application/lib/add-e2e.js +3 -27
  26. package/src/generators/application/lib/add-linting.js +16 -13
  27. package/src/generators/application/lib/add-project.js +33 -43
  28. package/src/generators/application/lib/create-application-files.helpers.js +5 -67
  29. package/src/generators/application/lib/create-application-files.js +11 -23
  30. package/src/generators/application/lib/normalize-options.d.ts +0 -3
  31. package/src/generators/application/lib/normalize-options.js +0 -31
  32. package/src/generators/application/schema.d.ts +0 -2
  33. package/src/generators/application/schema.json +3 -9
  34. package/src/generators/component/component.d.ts +4 -4
  35. package/src/generators/component/component.js +2 -3
  36. package/src/generators/component/schema.json +7 -7
  37. package/src/generators/custom-server/custom-server.d.ts +1 -1
  38. package/src/generators/custom-server/custom-server.js +9 -34
  39. package/src/generators/custom-server/files/server/main.ts__tmpl__ +4 -4
  40. package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +0 -2
  41. package/src/generators/custom-server/schema.json +1 -1
  42. package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +0 -1
  43. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +10 -23
  44. package/src/generators/cypress-component-configuration/schema.d.ts +0 -1
  45. package/src/generators/cypress-component-configuration/schema.json +1 -1
  46. package/src/generators/init/init.d.ts +3 -4
  47. package/src/generators/init/init.js +44 -30
  48. package/src/generators/init/schema.d.ts +4 -3
  49. package/src/generators/init/schema.json +23 -11
  50. package/src/generators/library/lib/normalize-options.js +0 -5
  51. package/src/generators/library/library.js +1 -19
  52. package/src/generators/library/schema.d.ts +1 -2
  53. package/src/generators/library/schema.json +3 -3
  54. package/src/generators/page/page.js +4 -21
  55. package/src/generators/page/schema.d.ts +3 -3
  56. package/src/generators/page/schema.json +5 -5
  57. package/src/utils/add-gitignore-entry.js +1 -1
  58. package/src/utils/styles.d.ts +4 -4
  59. package/src/utils/types.d.ts +0 -1
  60. package/src/utils/versions.d.ts +2 -6
  61. package/src/utils/versions.js +3 -7
  62. package/plugin.d.ts +0 -1
  63. package/plugin.js +0 -5
  64. package/src/generators/application/lib/add-plugin.d.ts +0 -2
  65. package/src/generators/application/lib/add-plugin.js +0 -25
  66. package/src/generators/init/lib/add-plugin.d.ts +0 -2
  67. package/src/generators/init/lib/add-plugin.js +0 -26
  68. package/src/migrations/update-17-2-7/remove-eslint-rules-patch.d.ts +0 -2
  69. package/src/migrations/update-17-2-7/remove-eslint-rules-patch.js +0 -15
  70. package/src/plugins/plugin.d.ts +0 -11
  71. package/src/plugins/plugin.js +0 -184
  72. package/src/utils/add-swc-to-custom-server.d.ts +0 -2
  73. package/src/utils/add-swc-to-custom-server.js +0 -37
@@ -4,13 +4,10 @@ exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const library_1 = require("@nx/react/src/generators/library/library");
6
6
  const js_1 = require("@nx/js");
7
- const versions_1 = require("@nx/react/src/utils/versions");
8
7
  const init_1 = require("../init/init");
9
8
  const normalize_options_1 = require("./lib/normalize-options");
10
- const versions_2 = require("../../utils/versions");
11
9
  async function libraryGenerator(host, rawOptions) {
12
10
  return await libraryGeneratorInternal(host, {
13
- addPlugin: false,
14
11
  projectNameAndRootFormat: 'derived',
15
12
  ...rawOptions,
16
13
  });
@@ -19,14 +16,9 @@ exports.libraryGenerator = libraryGenerator;
19
16
  async function libraryGeneratorInternal(host, rawOptions) {
20
17
  const options = await (0, normalize_options_1.normalizeOptions)(host, rawOptions);
21
18
  const tasks = [];
22
- const jsInitTask = await (0, js_1.initGenerator)(host, {
23
- js: options.js,
24
- skipPackageJson: options.skipPackageJson,
25
- skipFormat: true,
26
- });
27
- tasks.push(jsInitTask);
28
19
  const initTask = await (0, init_1.nextInitGenerator)(host, {
29
20
  ...options,
21
+ e2eTestRunner: 'none',
30
22
  skipFormat: true,
31
23
  });
32
24
  tasks.push(initTask);
@@ -36,16 +28,6 @@ async function libraryGeneratorInternal(host, rawOptions) {
36
28
  skipFormat: true,
37
29
  });
38
30
  tasks.push(libTask);
39
- if (!options.skipPackageJson) {
40
- const devDependencies = {};
41
- if (options.linter === 'eslint') {
42
- devDependencies['eslint-config-next'] = versions_2.eslintConfigNextVersion;
43
- }
44
- if (options.unitTestRunner && options.unitTestRunner !== 'none') {
45
- devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
46
- }
47
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { tslib: versions_2.tsLibVersion }, devDependencies));
48
- }
49
31
  const indexPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src', `index.${options.js ? 'js' : 'ts'}`);
50
32
  const indexContent = host.read(indexPath, 'utf-8');
51
33
  host.write(indexPath, `// Use this file to export React client components (e.g. those with 'use client' directive) or other non-server utilities\n${indexContent}`);
@@ -1,4 +1,4 @@
1
- import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
2
2
  import type { Linter } from '@nx/eslint';
3
3
  import type { SupportedStyles } from '@nx/react';
4
4
 
@@ -24,5 +24,4 @@ export interface Schema {
24
24
  strict?: boolean;
25
25
  setParserOptionsProject?: boolean;
26
26
  skipPackageJson?: boolean;
27
- addPlugin?: boolean;
28
27
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxReactLibrary",
5
5
  "title": "Create a React Library for Nx",
@@ -40,11 +40,11 @@
40
40
  { "value": "css", "label": "CSS" },
41
41
  {
42
42
  "value": "scss",
43
- "label": "SASS(.scss) [ https://sass-lang.com ]"
43
+ "label": "SASS(.scss) [ http://sass-lang.com ]"
44
44
  },
45
45
  {
46
46
  "value": "less",
47
- "label": "LESS [ https://lesscss.org ]"
47
+ "label": "LESS [ http://lesscss.org ]"
48
48
  },
49
49
  {
50
50
  "value": "styled-components",
@@ -21,8 +21,7 @@ async function pageGeneratorInternal(host, schema) {
21
21
  const options = await normalizeOptions(host, schema);
22
22
  const componentTask = await (0, react_1.componentGenerator)(host, {
23
23
  ...options,
24
- isNextPage: true,
25
- nameAndDirectoryFormat: 'as-provided', // already determined the directory so use as is
24
+ nameAndDirectoryFormat: 'as-provided',
26
25
  export: false,
27
26
  classComponent: false,
28
27
  routing: false,
@@ -43,34 +42,18 @@ exports.pageGeneratorInternal = pageGeneratorInternal;
43
42
  async function normalizeOptions(host, options) {
44
43
  let isAppRouter;
45
44
  let derivedDirectory;
46
- let routerDirectory;
47
45
  if (options.project) {
48
46
  // Legacy behavior, detect app vs page router from specified project.
49
- // TODO(v19): remove this logic
47
+ // TODO(v18): remove this logic
50
48
  const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
51
49
  // app/ is a reserved folder in nextjs so it is safe to check it's existence
52
- isAppRouter =
53
- host.exists(`${project.root}/app`) ||
54
- host.exists(`${project.root}/src/app`);
55
- routerDirectory = isAppRouter ? 'app' : 'pages';
50
+ isAppRouter = host.exists(`${project.root}/app`);
51
+ const routerDirectory = isAppRouter ? 'app' : 'pages';
56
52
  derivedDirectory = options.directory
57
53
  ? `${routerDirectory}/${options.directory}`
58
54
  : `${routerDirectory}`;
59
55
  }
60
56
  else {
61
- // Get the project name first so we can determine the router directory
62
- const { project: determinedProjectName } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
63
- artifactType: 'page',
64
- callingGenerator: '@nx/next:page',
65
- name: options.name,
66
- directory: options.directory,
67
- });
68
- const project = (0, devkit_1.readProjectConfiguration)(host, determinedProjectName);
69
- // app/ is a reserved folder in nextjs so it is safe to check it's existence
70
- isAppRouter =
71
- host.exists(`${project.root}/app`) ||
72
- host.exists(`${project.root}/src/app`);
73
- routerDirectory = isAppRouter ? 'app' : 'pages';
74
57
  // New behavior, use directory as is without detecting whether we're using app or pages router.
75
58
  derivedDirectory = options.directory;
76
59
  }
@@ -3,16 +3,16 @@ import { SupportedStyles } from '@nx/react';
3
3
  export interface Schema {
4
4
  name: string;
5
5
  /**
6
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19.
6
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18.
7
7
  */
8
- project?: string;
8
+ project: string;
9
9
  style: SupportedStyles;
10
10
  directory?: string;
11
11
  fileName?: string;
12
12
  withTests?: boolean;
13
13
  js?: boolean;
14
14
  /**
15
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
15
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18.
16
16
  */
17
17
  flat?: boolean;
18
18
  skipFormat?: boolean;
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxNextReactPage",
5
5
  "title": "Create a Page for Next",
@@ -13,7 +13,7 @@
13
13
  "$default": {
14
14
  "$source": "projectName"
15
15
  },
16
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19."
16
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
17
17
  },
18
18
  "name": {
19
19
  "type": "string",
@@ -51,11 +51,11 @@
51
51
  },
52
52
  {
53
53
  "value": "scss",
54
- "label": "SASS(.scss) [ https://sass-lang.com ]"
54
+ "label": "SASS(.scss) [ http://sass-lang.com ]"
55
55
  },
56
56
  {
57
57
  "value": "less",
58
- "label": "LESS [ https://lesscss.org ]"
58
+ "label": "LESS [ http://lesscss.org ]"
59
59
  },
60
60
  {
61
61
  "value": "styled-components",
@@ -97,7 +97,7 @@
97
97
  "type": "boolean",
98
98
  "description": "Create component at the source root rather than its own directory.",
99
99
  "default": false,
100
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19."
100
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
101
101
  },
102
102
  "skipFormat": {
103
103
  "description": "Skip formatting files.",
@@ -10,7 +10,7 @@ function addGitIgnoreEntry(host) {
10
10
  const ig = (0, ignore_1.default)();
11
11
  ig.add(host.read('.gitignore', 'utf-8'));
12
12
  if (!ig.ignores('apps/example/.next')) {
13
- content = `${content}\n\n# Next.js\n.next\nout\n`;
13
+ content = `${content}\n\n# Next.js\n.next\n`;
14
14
  }
15
15
  host.write('.gitignore', content);
16
16
  }
@@ -1,7 +1,7 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  export declare const nextSpecificStyleDependenciesBabel: {
3
3
  'styled-components': {
4
- dependencies: import("@nx/react/src/utils/dependencies").DependencyEntries;
4
+ dependencies: import("../../../../build/packages/react/src/utils/dependencies").DependencyEntries;
5
5
  devDependencies: {
6
6
  'babel-plugin-styled-components': string;
7
7
  };
@@ -10,7 +10,7 @@ export declare const nextSpecificStyleDependenciesBabel: {
10
10
  dependencies: {
11
11
  '@emotion/server': string;
12
12
  };
13
- devDependencies: import("@nx/react/src/utils/dependencies").DependencyEntries;
13
+ devDependencies: import("../../../../build/packages/react/src/utils/dependencies").DependencyEntries;
14
14
  };
15
15
  css: {
16
16
  dependencies: {};
@@ -32,7 +32,7 @@ export declare const nextSpecificStyleDependenciesBabel: {
32
32
  };
33
33
  export declare const nextSpecificStyleDependenciesSwc: {
34
34
  'styled-components': {
35
- dependencies: import("@nx/react/src/utils/dependencies").DependencyEntries;
35
+ dependencies: import("../../../../build/packages/react/src/utils/dependencies").DependencyEntries;
36
36
  devDependencies: {
37
37
  'babel-plugin-styled-components': string;
38
38
  };
@@ -41,7 +41,7 @@ export declare const nextSpecificStyleDependenciesSwc: {
41
41
  dependencies: {
42
42
  '@emotion/server': string;
43
43
  };
44
- devDependencies: import("@nx/react/src/utils/dependencies").DependencyEntries;
44
+ devDependencies: import("../../../../build/packages/react/src/utils/dependencies").DependencyEntries;
45
45
  };
46
46
  css: {
47
47
  dependencies: {};
@@ -44,7 +44,6 @@ export interface NextServeBuilderOptions {
44
44
  buildLibsFromSource?: boolean;
45
45
  keepAliveTimeout?: number;
46
46
  turbo?: boolean;
47
- experimentalHttps?: boolean;
48
47
  }
49
48
  export interface NextExportBuilderOptions {
50
49
  buildTarget: string;
@@ -1,12 +1,8 @@
1
1
  export declare const nxVersion: any;
2
- export declare const nextVersion = "14.0.4";
3
- export declare const eslintConfigNextVersion = "14.0.4";
2
+ export declare const nextVersion = "13.4.1";
3
+ export declare const eslintConfigNextVersion = "13.4.1";
4
4
  export declare const sassVersion = "1.62.1";
5
5
  export declare const lessLoader = "11.1.0";
6
6
  export declare const emotionServerVersion = "11.11.0";
7
7
  export declare const babelPluginStyledComponentsVersion = "1.10.7";
8
8
  export declare const tsLibVersion = "^2.3.0";
9
- export declare const swcCliVersion = "~0.1.62";
10
- export declare const swcCoreVersion = "~1.3.85";
11
- export declare const swcHelpersVersion = "~0.5.2";
12
- export declare const swcNodeVersion = "~1.8.0";
@@ -1,15 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.swcNodeVersion = exports.swcHelpersVersion = exports.swcCoreVersion = exports.swcCliVersion = exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.emotionServerVersion = exports.lessLoader = exports.sassVersion = exports.eslintConfigNextVersion = exports.nextVersion = exports.nxVersion = void 0;
3
+ exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.emotionServerVersion = exports.lessLoader = exports.sassVersion = exports.eslintConfigNextVersion = exports.nextVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
- exports.nextVersion = '14.0.4';
6
- exports.eslintConfigNextVersion = '14.0.4';
5
+ exports.nextVersion = '13.4.1';
6
+ exports.eslintConfigNextVersion = '13.4.1';
7
7
  exports.sassVersion = '1.62.1';
8
8
  exports.lessLoader = '11.1.0';
9
9
  exports.emotionServerVersion = '11.11.0';
10
10
  exports.babelPluginStyledComponentsVersion = '1.10.7';
11
11
  exports.tsLibVersion = '^2.3.0';
12
- exports.swcCliVersion = '~0.1.62';
13
- exports.swcCoreVersion = '~1.3.85';
14
- exports.swcHelpersVersion = '~0.5.2';
15
- exports.swcNodeVersion = '~1.8.0';
package/plugin.d.ts DELETED
@@ -1 +0,0 @@
1
- export { createNodes, NextPluginOptions } from './src/plugins/plugin';
package/plugin.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodes = void 0;
4
- var plugin_1 = require("./src/plugins/plugin");
5
- Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function addPlugin(tree: Tree): void;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addPlugin = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- function addPlugin(tree) {
6
- const nxJson = (0, devkit_1.readNxJson)(tree);
7
- nxJson.plugins ??= [];
8
- for (const plugin of nxJson.plugins) {
9
- if (typeof plugin === 'string'
10
- ? plugin === '@nx/next/plugin'
11
- : plugin.plugin === '@nx/next/plugin') {
12
- return;
13
- }
14
- }
15
- nxJson.plugins.push({
16
- plugin: '@nx/next/plugin',
17
- options: {
18
- buildTargetName: 'build',
19
- serveTargetName: 'serve',
20
- exportTargetName: 'export',
21
- },
22
- });
23
- (0, devkit_1.updateNxJson)(tree, nxJson);
24
- }
25
- exports.addPlugin = addPlugin;
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function addPlugin(tree: Tree): void;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addPlugin = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- function addPlugin(tree) {
6
- const nxJson = (0, devkit_1.readNxJson)(tree);
7
- nxJson.plugins ??= [];
8
- for (const plugin of nxJson.plugins) {
9
- if (typeof plugin === 'string'
10
- ? plugin === '@nx/next/plugin'
11
- : plugin.plugin === '@nx/next/plugin') {
12
- return;
13
- }
14
- }
15
- nxJson.plugins.push({
16
- plugin: '@nx/next/plugin',
17
- options: {
18
- buildTargetName: 'build',
19
- devTargetName: 'dev',
20
- startTargetName: 'start',
21
- serveStaticTargetName: 'serve-static',
22
- },
23
- });
24
- (0, devkit_1.updateNxJson)(tree, nxJson);
25
- }
26
- exports.addPlugin = addPlugin;
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function update(tree: Tree): Promise<void>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const devkit_1 = require("@nx/devkit");
4
- const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
5
- async function update(tree) {
6
- const projects = (0, devkit_1.getProjects)(tree);
7
- projects.forEach((project) => {
8
- if (!(0, eslint_file_1.isEslintConfigSupported)(tree, project.root))
9
- return;
10
- (0, eslint_file_1.updateOverrideInLintConfig)(tree, project.root, (o) => o.rules?.['@next/next/no-html-link-for-pages'] &&
11
- o.files?.includes('**/*.*'), (o) => undefined);
12
- });
13
- await (0, devkit_1.formatFiles)(tree);
14
- }
15
- exports.default = update;
@@ -1,11 +0,0 @@
1
- /// <reference types="node" />
2
- import { CreateDependencies, CreateNodes } from '@nx/devkit';
3
- export interface NextPluginOptions {
4
- buildTargetName?: string;
5
- devTargetName?: string;
6
- startTargetName?: string;
7
- serveStaticTargetName?: string;
8
- }
9
- export declare const createDependencies: CreateDependencies;
10
- export declare const createNodes: CreateNodes<NextPluginOptions>;
11
- export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;
@@ -1,184 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadEsmModule = exports.createNodes = exports.createDependencies = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("path");
6
- const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
7
- const fs_1 = require("fs");
8
- const cache_directory_1 = require("nx/src/utils/cache-directory");
9
- const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
10
- const js_1 = require("@nx/js");
11
- const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'next.hash');
12
- const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
13
- const calculatedTargets = {};
14
- function readTargetsCache() {
15
- return (0, devkit_1.readJsonFile)(cachePath);
16
- }
17
- function writeTargetsToCache(targets) {
18
- (0, devkit_1.writeJsonFile)(cachePath, targets);
19
- }
20
- const createDependencies = () => {
21
- writeTargetsToCache(calculatedTargets);
22
- return [];
23
- };
24
- exports.createDependencies = createDependencies;
25
- exports.createNodes = [
26
- '**/next.config.{js,cjs,mjs}',
27
- async (configFilePath, options, context) => {
28
- const projectRoot = (0, path_1.dirname)(configFilePath);
29
- // Do not create a project if package.json and project.json isn't there.
30
- const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
31
- if (!siblingFiles.includes('package.json') &&
32
- !siblingFiles.includes('project.json')) {
33
- return {};
34
- }
35
- options = normalizeOptions(options);
36
- const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
37
- (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
38
- ]);
39
- const targets = targetsCache[hash] ??
40
- (await buildNextTargets(configFilePath, projectRoot, options, context));
41
- calculatedTargets[hash] = targets;
42
- return {
43
- projects: {
44
- [projectRoot]: {
45
- root: projectRoot,
46
- targets,
47
- },
48
- },
49
- };
50
- },
51
- ];
52
- async function buildNextTargets(nextConfigPath, projectRoot, options, context) {
53
- const nextConfig = await getNextConfig(nextConfigPath, context);
54
- const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
55
- const targets = {};
56
- targets[options.buildTargetName] = await getBuildTargetConfig(namedInputs, projectRoot, nextConfig);
57
- targets[options.devTargetName] = getDevTargetConfig(projectRoot);
58
- targets[options.startTargetName] = getStartTargetConfig(options, projectRoot);
59
- targets[options.serveStaticTargetName] = getStaticServeTargetConfig(options);
60
- return targets;
61
- }
62
- async function getBuildTargetConfig(namedInputs, projectRoot, nextConfig) {
63
- const nextOutputPath = await getOutputs(projectRoot, nextConfig);
64
- // Set output path here so that `withNx` can pick it up.
65
- const targetConfig = {
66
- command: `next build`,
67
- options: {
68
- cwd: projectRoot,
69
- },
70
- dependsOn: ['^build'],
71
- cache: true,
72
- inputs: getInputs(namedInputs),
73
- outputs: [nextOutputPath, `${nextOutputPath}/!(cache)`],
74
- };
75
- return targetConfig;
76
- }
77
- function getDevTargetConfig(projectRoot) {
78
- const targetConfig = {
79
- command: `next dev`,
80
- options: {
81
- cwd: projectRoot,
82
- },
83
- };
84
- return targetConfig;
85
- }
86
- function getStartTargetConfig(options, projectRoot) {
87
- const targetConfig = {
88
- command: `next start`,
89
- options: {
90
- cwd: projectRoot,
91
- },
92
- dependsOn: [options.buildTargetName],
93
- };
94
- return targetConfig;
95
- }
96
- function getStaticServeTargetConfig(options) {
97
- const targetConfig = {
98
- executor: '@nx/web:file-server',
99
- options: {
100
- buildTarget: options.buildTargetName,
101
- staticFilePath: '{projectRoot}/out',
102
- port: 3000,
103
- // Routes are found correctly with serve-static
104
- spa: false,
105
- },
106
- };
107
- return targetConfig;
108
- }
109
- async function getOutputs(projectRoot, nextConfig) {
110
- let dir = '.next';
111
- const { PHASE_PRODUCTION_BUILD } = require('next/constants');
112
- if (typeof nextConfig === 'function') {
113
- // Works for both async and sync functions.
114
- const configResult = await Promise.resolve(nextConfig(PHASE_PRODUCTION_BUILD, { defaultConfig: {} }));
115
- if (configResult?.distDir) {
116
- dir = configResult?.distDir;
117
- }
118
- }
119
- else if (typeof nextConfig === 'object' && nextConfig?.distDir) {
120
- // If nextConfig is an object, directly use its 'distDir' property.
121
- dir = nextConfig.distDir;
122
- }
123
- if (projectRoot === '.') {
124
- return `{projectRoot}/${dir}`;
125
- }
126
- else {
127
- return `{workspaceRoot}/${projectRoot}/${dir}`;
128
- }
129
- }
130
- async function getNextConfig(configFilePath, context) {
131
- const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
132
- let module;
133
- if ((0, path_1.extname)(configFilePath) === '.mjs') {
134
- module = await loadEsmModule(resolvedPath);
135
- }
136
- else {
137
- module = load(resolvedPath);
138
- }
139
- return module.default ?? module;
140
- }
141
- function normalizeOptions(options) {
142
- options ??= {};
143
- options.buildTargetName ??= 'build';
144
- options.devTargetName ??= 'dev';
145
- options.startTargetName ??= 'start';
146
- options.serveStaticTargetName ??= 'serve-static';
147
- return options;
148
- }
149
- function getInputs(namedInputs) {
150
- return [
151
- ...('production' in namedInputs
152
- ? ['default', '^production']
153
- : ['default', '^default']),
154
- {
155
- externalDependencies: ['next'],
156
- },
157
- ];
158
- }
159
- const packageInstallationDirectories = ['node_modules', '.yarn'];
160
- /**
161
- * Load the module after ensuring that the require cache is cleared.
162
- */
163
- function load(path) {
164
- // Clear cache if the path is in the cache
165
- if (require.cache[path]) {
166
- for (const key of Object.keys(require.cache)) {
167
- if (!packageInstallationDirectories.some((dir) => key.includes(dir))) {
168
- delete require.cache[key];
169
- }
170
- }
171
- }
172
- // Then require
173
- return require(path);
174
- }
175
- /**
176
- * Lazily compiled dynamic import loader function.
177
- */
178
- let dynamicLoad;
179
- function loadEsmModule(modulePath) {
180
- const modulePathWithCacheBust = `${modulePath}?version=${Date.now()}`;
181
- dynamicLoad ??= new Function('modulePath', `return import(modulePath);`);
182
- return dynamicLoad(modulePathWithCacheBust);
183
- }
184
- exports.loadEsmModule = loadEsmModule;
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function configureForSwc(tree: Tree, projectRoot: string): () => void;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configureForSwc = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const versions_1 = require("./versions");
6
- const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
7
- function configureForSwc(tree, projectRoot) {
8
- const swcConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, '.swcrc');
9
- const rootPackageJson = (0, devkit_1.readJson)(tree, 'package.json');
10
- const hasSwcDepedency = rootPackageJson.dependencies?.['@swc/core'] ||
11
- rootPackageJson.devDependencies?.['@swc/core'];
12
- const hasSwcCliDependency = rootPackageJson.dependencies?.['@swc/cli'] ||
13
- rootPackageJson.devDependencies?.['@swc/cli'];
14
- if (!tree.exists(swcConfigPath)) {
15
- (0, add_swc_config_1.addSwcConfig)(tree, projectRoot);
16
- }
17
- if (tree.exists(swcConfigPath)) {
18
- (0, devkit_1.updateJson)(tree, swcConfigPath, (json) => {
19
- return {
20
- ...json,
21
- exclude: [...json.exclude, '.*.d.ts$'],
22
- };
23
- });
24
- }
25
- if (!hasSwcDepedency || !hasSwcCliDependency) {
26
- addSwcDependencies(tree);
27
- return () => (0, devkit_1.installPackagesTask)(tree);
28
- }
29
- }
30
- exports.configureForSwc = configureForSwc;
31
- function addSwcDependencies(tree) {
32
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
33
- '@swc-node/register': versions_1.swcNodeVersion,
34
- '@swc/cli': versions_1.swcCliVersion,
35
- '@swc/core': versions_1.swcCoreVersion,
36
- });
37
- }