@nx/next 0.0.0-pr-22179-271588f

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 (158) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/babel.d.ts +0 -0
  4. package/babel.js +12 -0
  5. package/executors.json +20 -0
  6. package/generators.json +47 -0
  7. package/index.d.ts +8 -0
  8. package/index.js +19 -0
  9. package/migrations.json +106 -0
  10. package/package.json +60 -0
  11. package/plugin.d.ts +1 -0
  12. package/plugin.js +5 -0
  13. package/plugins/component-testing.d.ts +2 -0
  14. package/plugins/component-testing.js +96 -0
  15. package/plugins/with-less.d.ts +3 -0
  16. package/plugins/with-less.js +79 -0
  17. package/plugins/with-nx.d.ts +25 -0
  18. package/plugins/with-nx.js +297 -0
  19. package/plugins/with-stylus.d.ts +3 -0
  20. package/plugins/with-stylus.js +12 -0
  21. package/src/executors/build/build.impl.d.ts +5 -0
  22. package/src/executors/build/build.impl.js +106 -0
  23. package/src/executors/build/lib/check-project.d.ts +1 -0
  24. package/src/executors/build/lib/check-project.js +12 -0
  25. package/src/executors/build/lib/create-next-config-file.d.ts +14 -0
  26. package/src/executors/build/lib/create-next-config-file.js +162 -0
  27. package/src/executors/build/lib/test-fixtures/ensure-exts/baz.json +1 -0
  28. package/src/executors/build/lib/update-package-json.d.ts +3 -0
  29. package/src/executors/build/lib/update-package-json.js +30 -0
  30. package/src/executors/build/schema.json +76 -0
  31. package/src/executors/export/export.impl.d.ts +17 -0
  32. package/src/executors/export/export.impl.js +58 -0
  33. package/src/executors/export/schema.json +30 -0
  34. package/src/executors/server/custom-server.impl.d.ts +6 -0
  35. package/src/executors/server/custom-server.impl.js +36 -0
  36. package/src/executors/server/schema.json +63 -0
  37. package/src/executors/server/server.impl.d.ts +6 -0
  38. package/src/executors/server/server.impl.js +66 -0
  39. package/src/generators/application/application.d.ts +4 -0
  40. package/src/generators/application/application.js +85 -0
  41. package/src/generators/application/files/app/api/hello/route.ts__tmpl__ +4 -0
  42. package/src/generators/application/files/app/global.__stylesExt____tmpl__ +1 -0
  43. package/src/generators/application/files/app/page.module.__style__ +1 -0
  44. package/src/generators/application/files/app/page.tsx__tmpl__ +30 -0
  45. package/src/generators/application/files/app-default-layout/layout.tsx__tmpl__ +18 -0
  46. package/src/generators/application/files/app-styled-components/layout.tsx__tmpl__ +21 -0
  47. package/src/generators/application/files/app-styled-components/registry.tsx__tmpl__ +33 -0
  48. package/src/generators/application/files/app-styled-jsx/layout.tsx__tmpl__ +16 -0
  49. package/src/generators/application/files/app-styled-jsx/registry.tsx__tmpl__ +23 -0
  50. package/src/generators/application/files/common/__dot__babelrc +21 -0
  51. package/src/generators/application/files/common/index.d.ts__tmpl__ +13 -0
  52. package/src/generators/application/files/common/next-env.d.ts__tmpl__ +5 -0
  53. package/src/generators/application/files/common/next.config.js__tmpl__ +82 -0
  54. package/src/generators/application/files/common/public/.gitkeep +0 -0
  55. package/src/generators/application/files/common/public/favicon.ico +0 -0
  56. package/src/generators/application/files/common/specs/__fileName__.spec.tsx__tmpl__ +18 -0
  57. package/src/generators/application/files/common/tsconfig.json__tmpl__ +29 -0
  58. package/src/generators/application/files/pages/__fileName__.module.__style__ +1 -0
  59. package/src/generators/application/files/pages/__fileName__.tsx__tmpl__ +30 -0
  60. package/src/generators/application/files/pages/_app.tsx__tmpl__ +18 -0
  61. package/src/generators/application/files/pages/_document.tsx__tmpl__ +33 -0
  62. package/src/generators/application/files/pages/styles.__stylesExt____tmpl__ +1 -0
  63. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  64. package/src/generators/application/lib/add-e2e.js +72 -0
  65. package/src/generators/application/lib/add-jest.d.ts +3 -0
  66. package/src/generators/application/lib/add-jest.js +38 -0
  67. package/src/generators/application/lib/add-linting.d.ts +3 -0
  68. package/src/generators/application/lib/add-linting.js +62 -0
  69. package/src/generators/application/lib/add-plugin.d.ts +2 -0
  70. package/src/generators/application/lib/add-plugin.js +25 -0
  71. package/src/generators/application/lib/add-project.d.ts +3 -0
  72. package/src/generators/application/lib/add-project.js +66 -0
  73. package/src/generators/application/lib/create-application-files.d.ts +3 -0
  74. package/src/generators/application/lib/create-application-files.helpers.d.ts +2 -0
  75. package/src/generators/application/lib/create-application-files.helpers.js +846 -0
  76. package/src/generators/application/lib/create-application-files.js +114 -0
  77. package/src/generators/application/lib/normalize-options.d.ts +14 -0
  78. package/src/generators/application/lib/normalize-options.js +56 -0
  79. package/src/generators/application/lib/set-defaults.d.ts +3 -0
  80. package/src/generators/application/lib/set-defaults.js +14 -0
  81. package/src/generators/application/lib/show-possible-warnings.d.ts +3 -0
  82. package/src/generators/application/lib/show-possible-warnings.js +10 -0
  83. package/src/generators/application/lib/update-cypress-tsconfig.d.ts +3 -0
  84. package/src/generators/application/lib/update-cypress-tsconfig.js +16 -0
  85. package/src/generators/application/lib/update-jest-config.d.ts +3 -0
  86. package/src/generators/application/lib/update-jest-config.js +15 -0
  87. package/src/generators/application/schema.d.ts +24 -0
  88. package/src/generators/application/schema.json +146 -0
  89. package/src/generators/component/component.d.ts +28 -0
  90. package/src/generators/component/component.js +66 -0
  91. package/src/generators/component/schema.json +125 -0
  92. package/src/generators/custom-server/custom-server.d.ts +3 -0
  93. package/src/generators/custom-server/custom-server.js +104 -0
  94. package/src/generators/custom-server/files/server/main.ts__tmpl__ +46 -0
  95. package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +17 -0
  96. package/src/generators/custom-server/schema.d.ts +4 -0
  97. package/src/generators/custom-server/schema.json +30 -0
  98. package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +5 -0
  99. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +87 -0
  100. package/src/generators/cypress-component-configuration/schema.d.ts +6 -0
  101. package/src/generators/cypress-component-configuration/schema.json +42 -0
  102. package/src/generators/init/init.d.ts +5 -0
  103. package/src/generators/init/init.js +46 -0
  104. package/src/generators/init/lib/add-plugin.d.ts +2 -0
  105. package/src/generators/init/lib/add-plugin.js +26 -0
  106. package/src/generators/init/schema.d.ts +7 -0
  107. package/src/generators/init/schema.json +34 -0
  108. package/src/generators/library/lib/normalize-options.d.ts +7 -0
  109. package/src/generators/library/lib/normalize-options.js +26 -0
  110. package/src/generators/library/library.d.ts +5 -0
  111. package/src/generators/library/library.js +92 -0
  112. package/src/generators/library/schema.d.ts +28 -0
  113. package/src/generators/library/schema.json +156 -0
  114. package/src/generators/page/page.d.ts +5 -0
  115. package/src/generators/page/page.js +96 -0
  116. package/src/generators/page/schema.d.ts +20 -0
  117. package/src/generators/page/schema.json +111 -0
  118. package/src/migrations/update-15-8-8/add-style-packages.d.ts +3 -0
  119. package/src/migrations/update-15-8-8/add-style-packages.js +23 -0
  120. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  121. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  122. package/src/migrations/update-16-3-0/remove-root-build-option.d.ts +2 -0
  123. package/src/migrations/update-16-3-0/remove-root-build-option.js +17 -0
  124. package/src/migrations/update-16-4-0/update-nx-next-dependency.d.ts +2 -0
  125. package/src/migrations/update-16-4-0/update-nx-next-dependency.js +17 -0
  126. package/src/migrations/update-17-2-7/remove-eslint-rules-patch.d.ts +2 -0
  127. package/src/migrations/update-17-2-7/remove-eslint-rules-patch.js +15 -0
  128. package/src/plugins/plugin.d.ts +11 -0
  129. package/src/plugins/plugin.js +182 -0
  130. package/src/utils/add-gitignore-entry.d.ts +2 -0
  131. package/src/utils/add-gitignore-entry.js +17 -0
  132. package/src/utils/add-swc-to-custom-server.d.ts +2 -0
  133. package/src/utils/add-swc-to-custom-server.js +37 -0
  134. package/src/utils/compose-plugins.d.ts +3 -0
  135. package/src/utils/compose-plugins.js +22 -0
  136. package/src/utils/config-invalid-function.fixture.d.ts +0 -0
  137. package/src/utils/config-invalid-function.fixture.js +1 -0
  138. package/src/utils/config-not-a-function.fixture.d.ts +0 -0
  139. package/src/utils/config-not-a-function.fixture.js +1 -0
  140. package/src/utils/config.d.ts +13 -0
  141. package/src/utils/config.js +24 -0
  142. package/src/utils/constants.d.ts +1 -0
  143. package/src/utils/constants.js +4 -0
  144. package/src/utils/create-cli-options.d.ts +1 -0
  145. package/src/utils/create-cli-options.js +13 -0
  146. package/src/utils/create-copy-plugin.d.ts +2 -0
  147. package/src/utils/create-copy-plugin.js +64 -0
  148. package/src/utils/generate-globs.d.ts +5 -0
  149. package/src/utils/generate-globs.js +29 -0
  150. package/src/utils/styles.d.ts +67 -0
  151. package/src/utils/styles.js +67 -0
  152. package/src/utils/types.d.ts +57 -0
  153. package/src/utils/types.js +2 -0
  154. package/src/utils/versions.d.ts +12 -0
  155. package/src/utils/versions.js +15 -0
  156. package/tailwind.d.ts +2 -0
  157. package/tailwind.js +6 -0
  158. package/typings/image.d.ts +12 -0
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.customServerGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server");
7
+ async function customServerGenerator(host, options) {
8
+ const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
9
+ const nxJson = (0, devkit_1.readNxJson)(host);
10
+ const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
11
+ ? p === '@nx/next/plugin'
12
+ : p.plugin === '@nx/next/plugin');
13
+ if (project.targets?.build?.executor !== '@nx/next:build' &&
14
+ project.targets?.build?.executor !== '@nrwl/next:build' &&
15
+ !hasPlugin) {
16
+ devkit_1.logger.error(`Project ${options.project} is not a Next.js project. Did you generate it with "nx g @nx/next:app"?`);
17
+ return;
18
+ }
19
+ // In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
20
+ const outputPath = hasPlugin
21
+ ? `dist/${project.root}`
22
+ : project.targets?.build?.options?.outputPath;
23
+ const root = project.root;
24
+ if ((!root ||
25
+ !outputPath ||
26
+ !project.targets?.build?.configurations?.development ||
27
+ !project.targets?.build?.configurations?.production) &&
28
+ !hasPlugin) {
29
+ devkit_1.logger.error(`Project ${options.project} has invalid config. Did you generate it with "nx g @nx/next:app"?`);
30
+ return;
31
+ }
32
+ if (project.targets?.['build-custom-server'] ||
33
+ project.targets?.['serve-custom-server']) {
34
+ devkit_1.logger.warn(`Project ${options.project} has custom server targets already: build-custom-server, serve-custom-server. Remove these targets from project and try again.`);
35
+ return;
36
+ }
37
+ // In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
38
+ // So we need ensure the mapping is correct from dist to the project root
39
+ const projectPathFromDist = `../../${(0, devkit_1.offsetFromRoot)(project.root)}${project.root}`;
40
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files'), project.root, {
41
+ ...options,
42
+ hasPlugin,
43
+ projectPathFromDist,
44
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(project.root),
45
+ projectRoot: project.root,
46
+ tmpl: '',
47
+ });
48
+ if (!hasPlugin) {
49
+ project.targets.build.dependsOn = ['build-custom-server'];
50
+ project.targets.serve.options.customServerTarget = `${options.project}:serve-custom-server`;
51
+ project.targets.serve.configurations.development.customServerTarget = `${options.project}:serve-custom-server:development`;
52
+ project.targets.serve.configurations.production.customServerTarget = `${options.project}:serve-custom-server:production`;
53
+ }
54
+ else {
55
+ project.targets['build'] = {
56
+ dependsOn: ['^build', 'build-custom-server'],
57
+ };
58
+ }
59
+ project.targets['build-custom-server'] = {
60
+ executor: options.compiler === 'tsc' ? '@nx/js:tsc' : '@nx/js:swc',
61
+ defaultConfiguration: 'production',
62
+ options: {
63
+ outputPath,
64
+ main: `${root}/server/main.ts`,
65
+ tsConfig: `${root}/tsconfig.server.json`,
66
+ clean: false,
67
+ assets: [],
68
+ },
69
+ configurations: {
70
+ development: {},
71
+ production: {},
72
+ },
73
+ };
74
+ project.targets['serve-custom-server'] = {
75
+ executor: '@nx/js:node',
76
+ defaultConfiguration: 'production',
77
+ options: {
78
+ buildTarget: `${options.project}:build-custom-server`,
79
+ },
80
+ configurations: {
81
+ development: {
82
+ buildTarget: `${options.project}:build-custom-server:development`,
83
+ },
84
+ production: {
85
+ buildTarget: `${options.project}:build-custom-server:production`,
86
+ },
87
+ },
88
+ };
89
+ (0, devkit_1.updateProjectConfiguration)(host, options.project, project);
90
+ (0, devkit_1.updateJson)(host, 'nx.json', (json) => {
91
+ if (!json.tasksRunnerOptions?.default?.options?.cacheableOperations?.includes('build-custom-server') &&
92
+ json.tasksRunnerOptions?.default?.options?.cacheableOperations) {
93
+ json.tasksRunnerOptions.default.options.cacheableOperations.push('build-custom-server');
94
+ }
95
+ json.targetDefaults ??= {};
96
+ json.targetDefaults['build-custom-server'] ??= {};
97
+ json.targetDefaults['build-custom-server'].cache ??= true;
98
+ return json;
99
+ });
100
+ if (options.compiler === 'swc') {
101
+ return (0, add_swc_to_custom_server_1.configureForSwc)(host, project.root);
102
+ }
103
+ }
104
+ exports.customServerGenerator = customServerGenerator;
@@ -0,0 +1,46 @@
1
+ /*
2
+ * This is only a minimal custom server to get started.
3
+ * You may want to consider using Express or another server framework, and enable security features such as CORS.
4
+ *
5
+ * For an example, see the Next.js repo:
6
+ * Node - https://github.com/vercel/next.js/blob/canary/examples/custom-server
7
+ */
8
+ import { createServer } from 'http';
9
+ import { parse } from 'node:url';
10
+ import * as path from 'path';
11
+ import next from 'next';
12
+
13
+ // Next.js server options:
14
+ // - The environment variable is set by `@nx/next:server` when running the dev server.
15
+ // - The fallback `__dirname` is for production builds.
16
+ // - Feel free to change this to suit your needs.
17
+
18
+ const dir = process.env.NX_NEXT_DIR || <%- hasPlugin ? `path.join(__dirname, '${projectPathFromDist}')` : `path.join(__dirname, '..')`; %>
19
+ const dev = process.env.NODE_ENV === 'development';
20
+
21
+ // HTTP Server options:
22
+ // - Feel free to change this to suit your needs.
23
+ const hostname = process.env.HOST || 'localhost';
24
+ const port = process.env.PORT ? parseInt(process.env.PORT) : 4200;
25
+
26
+ async function main() {
27
+ const nextApp = next({ dev, dir });
28
+ const handle = nextApp.getRequestHandler();
29
+
30
+ await nextApp.prepare();
31
+
32
+ const server = createServer((req, res) => {
33
+ const parsedUrl = parse(req.url ?? '', true);
34
+ handle(req, res, parsedUrl);
35
+ });
36
+
37
+ server.listen(port, hostname);
38
+
39
+ console.log(`[ ready ] on http://${hostname}:${port}`)
40
+ }
41
+
42
+ main().catch((err) => {
43
+ console.error(err);
44
+ process.exit(1);
45
+ });
46
+
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "noEmit": false,
6
+ "incremental": true,
7
+ <% if(hasPlugin && compiler === 'tsc') { %>
8
+ "tsBuildInfoFile": "<%= offsetFromRoot %>tmp/buildcache/<%= projectRoot %>/server",
9
+ <% } %>
10
+ "types": [
11
+ "node"
12
+ ]
13
+ },
14
+ "include": [
15
+ "server/**/*.ts"
16
+ ]
17
+ }
@@ -0,0 +1,4 @@
1
+ export interface CustomServerSchema {
2
+ project: string;
3
+ compiler?: 'tsc' | 'swc';
4
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxNextCustomServer",
5
+ "title": "Add custom server",
6
+ "description": "Add a custom server to existing Next.js application.",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "type": "string",
11
+ "description": "The name of the project.",
12
+ "alias": "p",
13
+ "$default": {
14
+ "$source": "argv",
15
+ "index": 0
16
+ },
17
+ "x-dropdown": "project",
18
+ "x-prompt": "What is the name of the project to set up a custom server for?",
19
+ "x-priority": "important"
20
+ },
21
+ "compiler": {
22
+ "type": "string",
23
+ "enum": ["tsc", "swc"],
24
+ "default": "tsc",
25
+ "description": "The compiler used to build the custom server."
26
+ }
27
+ },
28
+ "required": ["project"],
29
+ "examplesFile": "../../../docs/custom-server-examples.md"
30
+ }
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { CypressComponentConfigurationGeneratorSchema } from './schema';
3
+ export declare function cypressComponentConfiguration(tree: Tree, options: CypressComponentConfigurationGeneratorSchema): Promise<GeneratorCallback>;
4
+ export declare function cypressComponentConfigurationInternal(tree: Tree, options: CypressComponentConfigurationGeneratorSchema): Promise<GeneratorCallback>;
5
+ export default cypressComponentConfiguration;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cypressComponentConfigurationInternal = exports.cypressComponentConfiguration = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ct_utils_1 = require("@nx/react/src/utils/ct-utils");
6
+ const versions_1 = require("../../utils/versions");
7
+ const react_1 = require("@nx/react");
8
+ const path_1 = require("path");
9
+ function cypressComponentConfiguration(tree, options) {
10
+ return cypressComponentConfigurationInternal(tree, {
11
+ addPlugin: false,
12
+ ...options,
13
+ });
14
+ }
15
+ exports.cypressComponentConfiguration = cypressComponentConfiguration;
16
+ async function cypressComponentConfigurationInternal(tree, options) {
17
+ const tasks = [];
18
+ const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
19
+ tasks.push(await baseCyCtConfig(tree, {
20
+ project: options.project,
21
+ skipFormat: true,
22
+ framework: 'next',
23
+ jsx: true,
24
+ addPlugin: options.addPlugin,
25
+ }));
26
+ const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
27
+ tasks.push(await webpackInitGenerator(tree, {
28
+ skipFormat: true,
29
+ addPlugin: options.addPlugin,
30
+ }));
31
+ const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
32
+ tasks.push(ensureDependencies(tree, { compiler: 'swc', uiFramework: 'react' }));
33
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
34
+ if (projectConfig.targets?.['component-test']?.executor ===
35
+ '@nx/cypress:cypress') {
36
+ projectConfig.targets['component-test'].options = {
37
+ ...projectConfig.targets['component-test'].options,
38
+ skipServe: true,
39
+ };
40
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
41
+ }
42
+ await addFiles(tree, projectConfig, options);
43
+ if (!options.skipFormat) {
44
+ await (0, devkit_1.formatFiles)(tree);
45
+ }
46
+ return (0, devkit_1.runTasksInSerial)(...tasks);
47
+ }
48
+ exports.cypressComponentConfigurationInternal = cypressComponentConfigurationInternal;
49
+ async function addFiles(tree, projectConfig, opts) {
50
+ const { addMountDefinition, addDefaultCTConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/config'));
51
+ const ctFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
52
+ const updatedCommandFile = await addMountDefinition(tree.read(ctFile, 'utf-8'));
53
+ tree.write(ctFile, `import { mount } from 'cypress/react18';\nimport './styles.ct.css';\n${updatedCommandFile}`);
54
+ const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
55
+ const updatedCyConfig = await addDefaultCTConfig(tree.read(cyFile, 'utf-8'));
56
+ tree.write(cyFile, `import { nxComponentTestingPreset } from '@nx/next/plugins/component-testing';\n${updatedCyConfig}`);
57
+ const isUsingTailwind = ['js', 'cjs'].some((ext) => tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, `tailwind.config.${ext}`)));
58
+ tree.write((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'styles.ct.css'), `/* This is where you can load global styles to apply to all components. */
59
+ ${isUsingTailwind
60
+ ? `@tailwind base;
61
+ @tailwind components;
62
+ @tailwind utilities;`
63
+ : ''}
64
+ `);
65
+ if (opts.generateTests) {
66
+ const filePaths = [];
67
+ (0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot, (filePath) => {
68
+ const fromProjectRootPath = (0, path_1.relative)(projectConfig.root, filePath);
69
+ // we don't generate tests for pages/server-side/appDir components
70
+ if (fromProjectRootPath.includes('pages') ||
71
+ fromProjectRootPath.includes('server') ||
72
+ fromProjectRootPath.includes('app')) {
73
+ return;
74
+ }
75
+ if ((0, ct_utils_1.isComponent)(tree, filePath)) {
76
+ filePaths.push(filePath);
77
+ }
78
+ });
79
+ for (const filePath of filePaths) {
80
+ await (0, react_1.componentTestGenerator)(tree, {
81
+ project: opts.project,
82
+ componentPath: filePath,
83
+ });
84
+ }
85
+ }
86
+ }
87
+ exports.default = cypressComponentConfiguration;
@@ -0,0 +1,6 @@
1
+ export interface CypressComponentConfigurationGeneratorSchema {
2
+ project: string;
3
+ generateTests: boolean;
4
+ skipFormat?: boolean;
5
+ addPlugin?: boolean;
6
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "CypressComponentConfiguration",
5
+ "title": "NextJS Component Testing Configuration",
6
+ "description": "Add Cypress Componet Testing to an existing NextJS project.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/next:cypress-component-configuration --project=my-next-project",
11
+ "description": "Add component testing to your Next project"
12
+ },
13
+ {
14
+ "command": "nx g @nx/next:cypress-component-configuration --project=my-next-project --generate-tests",
15
+ "description": "Add component testing to your Next project and generate component tests for your existing components"
16
+ }
17
+ ],
18
+ "properties": {
19
+ "project": {
20
+ "type": "string",
21
+ "description": "The name of the project to add cypress component testing configuration to",
22
+ "x-dropdown": "projects",
23
+ "x-prompt": "What project should we add Cypress component testing to?",
24
+ "x-priority": "important"
25
+ },
26
+ "generateTests": {
27
+ "type": "boolean",
28
+ "description": "Generate default component tests for existing components in the project",
29
+ "x-prompt": "Automatically generate tests for components declared in this project?",
30
+ "default": false,
31
+ "x-priority": "important"
32
+ },
33
+ "skipFormat": {
34
+ "type": "boolean",
35
+ "description": "Skip formatting files",
36
+ "default": false,
37
+ "x-priority": "internal"
38
+ }
39
+ },
40
+ "required": ["project"],
41
+ "examplesFile": "../../../docs/cypress-component-configuration-examples.md"
42
+ }
@@ -0,0 +1,5 @@
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
+ import type { InitSchema } from './schema';
3
+ export declare function nextInitGenerator(tree: Tree, schema: InitSchema): Promise<GeneratorCallback>;
4
+ export declare function nextInitGeneratorInternal(host: Tree, schema: InitSchema): Promise<GeneratorCallback>;
5
+ export default nextInitGenerator;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nextInitGeneratorInternal = exports.nextInitGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
+ const versions_1 = require("@nx/react/src/utils/versions");
7
+ const add_gitignore_entry_1 = require("../../utils/add-gitignore-entry");
8
+ const versions_2 = require("../../utils/versions");
9
+ const add_plugin_1 = require("./lib/add-plugin");
10
+ function updateDependencies(host, schema) {
11
+ const tasks = [];
12
+ tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/next'], []));
13
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {
14
+ next: versions_2.nextVersion,
15
+ react: versions_1.reactVersion,
16
+ 'react-dom': versions_1.reactDomVersion,
17
+ }, {
18
+ '@nx/next': versions_2.nxVersion,
19
+ }, undefined, schema.keepExistingVersions));
20
+ return (0, devkit_1.runTasksInSerial)(...tasks);
21
+ }
22
+ function nextInitGenerator(tree, schema) {
23
+ return nextInitGeneratorInternal(tree, { addPlugin: false, ...schema });
24
+ }
25
+ exports.nextInitGenerator = nextInitGenerator;
26
+ async function nextInitGeneratorInternal(host, schema) {
27
+ const nxJson = (0, devkit_1.readNxJson)(host);
28
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
29
+ nxJson.useInferencePlugins !== false;
30
+ schema.addPlugin ??= addPluginDefault;
31
+ if (schema.addPlugin) {
32
+ (0, add_plugin_1.addPlugin)(host);
33
+ }
34
+ (0, add_gitignore_entry_1.addGitIgnoreEntry)(host);
35
+ let installTask = () => { };
36
+ if (!schema.skipPackageJson) {
37
+ installTask = updateDependencies(host, schema);
38
+ }
39
+ if (schema.updatePackageScripts) {
40
+ const { createNodes } = await Promise.resolve().then(() => require('../../plugins/plugin'));
41
+ await (0, update_package_scripts_1.updatePackageScripts)(host, createNodes);
42
+ }
43
+ return installTask;
44
+ }
45
+ exports.nextInitGeneratorInternal = nextInitGeneratorInternal;
46
+ exports.default = nextInitGenerator;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function addPlugin(tree: Tree): void;
@@ -0,0 +1,26 @@
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;
@@ -0,0 +1,7 @@
1
+ export interface InitSchema {
2
+ skipFormat?: boolean;
3
+ skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
5
+ updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
7
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxNextNgInit",
5
+ "title": "Init Next Plugin",
6
+ "description": "Init Next Plugin.",
7
+ "type": "object",
8
+ "properties": {
9
+ "skipFormat": {
10
+ "description": "Skip formatting files.",
11
+ "type": "boolean",
12
+ "default": false
13
+ },
14
+ "skipPackageJson": {
15
+ "type": "boolean",
16
+ "default": false,
17
+ "description": "Do not add dependencies to `package.json`.",
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
31
+ }
32
+ },
33
+ "required": []
34
+ }
@@ -0,0 +1,7 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Schema } from '../schema';
3
+ export interface NormalizedSchema extends Schema {
4
+ importPath: string;
5
+ projectRoot: string;
6
+ }
7
+ export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ async function normalizeOptions(host, options) {
7
+ const { projectRoot, importPath, projectNameAndRootFormat } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
+ name: options.name,
9
+ projectType: 'library',
10
+ directory: options.directory,
11
+ importPath: options.importPath,
12
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
13
+ callingGenerator: '@nx/next:library',
14
+ });
15
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
16
+ const nxJson = (0, devkit_1.readNxJson)(host);
17
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
18
+ nxJson.useInferencePlugins !== false;
19
+ options.addPlugin ??= addPlugin;
20
+ return {
21
+ ...options,
22
+ importPath,
23
+ projectRoot,
24
+ };
25
+ }
26
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function libraryGenerator(host: Tree, rawOptions: Schema): Promise<GeneratorCallback>;
4
+ export declare function libraryGeneratorInternal(host: Tree, rawOptions: Schema): Promise<GeneratorCallback>;
5
+ export default libraryGenerator;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const library_1 = require("@nx/react/src/generators/library/library");
6
+ const js_1 = require("@nx/js");
7
+ const versions_1 = require("@nx/react/src/utils/versions");
8
+ const init_1 = require("../init/init");
9
+ const normalize_options_1 = require("./lib/normalize-options");
10
+ const versions_2 = require("../../utils/versions");
11
+ async function libraryGenerator(host, rawOptions) {
12
+ return await libraryGeneratorInternal(host, {
13
+ addPlugin: false,
14
+ projectNameAndRootFormat: 'derived',
15
+ ...rawOptions,
16
+ });
17
+ }
18
+ exports.libraryGenerator = libraryGenerator;
19
+ async function libraryGeneratorInternal(host, rawOptions) {
20
+ const options = await (0, normalize_options_1.normalizeOptions)(host, rawOptions);
21
+ 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
+ const initTask = await (0, init_1.nextInitGenerator)(host, {
29
+ ...options,
30
+ skipFormat: true,
31
+ });
32
+ tasks.push(initTask);
33
+ const libTask = await (0, library_1.libraryGenerator)(host, {
34
+ ...options,
35
+ compiler: 'swc',
36
+ skipFormat: true,
37
+ });
38
+ 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
+ const indexPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src', `index.${options.js ? 'js' : 'ts'}`);
50
+ const indexContent = host.read(indexPath, 'utf-8');
51
+ 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}`);
52
+ // Additional entry for Next.js libraries so React Server Components are exported from a separate entry point.
53
+ // This is needed because RSC exported from `src/index.ts` will mark the entire file as server-only and throw an error when used from a client component.
54
+ // See: https://github.com/nrwl/nx/issues/15830
55
+ const serverEntryPath = (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'server.' + (options.js ? 'js' : 'ts'));
56
+ host.write((0, devkit_1.joinPathFragments)(options.projectRoot, 'src', `server.${options.js ? 'js' : 'ts'}`), `// Use this file to export React server components
57
+ export * from './lib/hello-server';`);
58
+ host.write((0, devkit_1.joinPathFragments)(options.projectRoot, 'src/lib', `hello-server.${options.js ? 'js' : 'tsx'}`), `// React server components are async so you make database or API calls.
59
+ export async function HelloServer() {
60
+ return <h1>Hello Server</h1>
61
+ }
62
+ `);
63
+ (0, js_1.addTsConfigPath)(host, `${options.importPath}/server`, [serverEntryPath]);
64
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
65
+ if (options.style === '@emotion/styled') {
66
+ json.compilerOptions.jsxImportSource = '@emotion/react';
67
+ }
68
+ return json;
69
+ });
70
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'), (json) => {
71
+ if (!json.compilerOptions) {
72
+ json.compilerOptions = {
73
+ types: [],
74
+ };
75
+ }
76
+ if (!json.compilerOptions.types) {
77
+ json.compilerOptions.types = [];
78
+ }
79
+ json.compilerOptions.types = [
80
+ ...json.compilerOptions.types,
81
+ 'next',
82
+ '@nx/next/typings/image.d.ts',
83
+ ];
84
+ return json;
85
+ });
86
+ if (!options.skipFormat) {
87
+ await (0, devkit_1.formatFiles)(host);
88
+ }
89
+ return (0, devkit_1.runTasksInSerial)(...tasks);
90
+ }
91
+ exports.libraryGeneratorInternal = libraryGeneratorInternal;
92
+ exports.default = libraryGenerator;
@@ -0,0 +1,28 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/eslint';
3
+ import type { SupportedStyles } from '@nx/react';
4
+
5
+ export interface Schema {
6
+ name: string;
7
+ directory?: string;
8
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
9
+ style: SupportedStyles;
10
+ skipTsConfig?: boolean;
11
+ skipFormat?: boolean;
12
+ tags?: string;
13
+ pascalCaseFiles?: boolean;
14
+ routing?: boolean;
15
+ appProject?: string;
16
+ unitTestRunner: 'jest' | 'none';
17
+ linter: Linter;
18
+ component?: boolean;
19
+ publishable?: boolean;
20
+ buildable?: boolean;
21
+ importPath?: string;
22
+ js?: boolean;
23
+ globalCss?: boolean;
24
+ strict?: boolean;
25
+ setParserOptionsProject?: boolean;
26
+ skipPackageJson?: boolean;
27
+ addPlugin?: boolean;
28
+ }