@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.
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/babel.d.ts +0 -0
- package/babel.js +12 -0
- package/executors.json +20 -0
- package/generators.json +47 -0
- package/index.d.ts +8 -0
- package/index.js +19 -0
- package/migrations.json +106 -0
- package/package.json +60 -0
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/plugins/component-testing.d.ts +2 -0
- package/plugins/component-testing.js +96 -0
- package/plugins/with-less.d.ts +3 -0
- package/plugins/with-less.js +79 -0
- package/plugins/with-nx.d.ts +25 -0
- package/plugins/with-nx.js +297 -0
- package/plugins/with-stylus.d.ts +3 -0
- package/plugins/with-stylus.js +12 -0
- package/src/executors/build/build.impl.d.ts +5 -0
- package/src/executors/build/build.impl.js +106 -0
- package/src/executors/build/lib/check-project.d.ts +1 -0
- package/src/executors/build/lib/check-project.js +12 -0
- package/src/executors/build/lib/create-next-config-file.d.ts +14 -0
- package/src/executors/build/lib/create-next-config-file.js +162 -0
- package/src/executors/build/lib/test-fixtures/ensure-exts/baz.json +1 -0
- package/src/executors/build/lib/update-package-json.d.ts +3 -0
- package/src/executors/build/lib/update-package-json.js +30 -0
- package/src/executors/build/schema.json +76 -0
- package/src/executors/export/export.impl.d.ts +17 -0
- package/src/executors/export/export.impl.js +58 -0
- package/src/executors/export/schema.json +30 -0
- package/src/executors/server/custom-server.impl.d.ts +6 -0
- package/src/executors/server/custom-server.impl.js +36 -0
- package/src/executors/server/schema.json +63 -0
- package/src/executors/server/server.impl.d.ts +6 -0
- package/src/executors/server/server.impl.js +66 -0
- package/src/generators/application/application.d.ts +4 -0
- package/src/generators/application/application.js +85 -0
- package/src/generators/application/files/app/api/hello/route.ts__tmpl__ +4 -0
- package/src/generators/application/files/app/global.__stylesExt____tmpl__ +1 -0
- package/src/generators/application/files/app/page.module.__style__ +1 -0
- package/src/generators/application/files/app/page.tsx__tmpl__ +30 -0
- package/src/generators/application/files/app-default-layout/layout.tsx__tmpl__ +18 -0
- package/src/generators/application/files/app-styled-components/layout.tsx__tmpl__ +21 -0
- package/src/generators/application/files/app-styled-components/registry.tsx__tmpl__ +33 -0
- package/src/generators/application/files/app-styled-jsx/layout.tsx__tmpl__ +16 -0
- package/src/generators/application/files/app-styled-jsx/registry.tsx__tmpl__ +23 -0
- package/src/generators/application/files/common/__dot__babelrc +21 -0
- package/src/generators/application/files/common/index.d.ts__tmpl__ +13 -0
- package/src/generators/application/files/common/next-env.d.ts__tmpl__ +5 -0
- package/src/generators/application/files/common/next.config.js__tmpl__ +82 -0
- package/src/generators/application/files/common/public/.gitkeep +0 -0
- package/src/generators/application/files/common/public/favicon.ico +0 -0
- package/src/generators/application/files/common/specs/__fileName__.spec.tsx__tmpl__ +18 -0
- package/src/generators/application/files/common/tsconfig.json__tmpl__ +29 -0
- package/src/generators/application/files/pages/__fileName__.module.__style__ +1 -0
- package/src/generators/application/files/pages/__fileName__.tsx__tmpl__ +30 -0
- package/src/generators/application/files/pages/_app.tsx__tmpl__ +18 -0
- package/src/generators/application/files/pages/_document.tsx__tmpl__ +33 -0
- package/src/generators/application/files/pages/styles.__stylesExt____tmpl__ +1 -0
- package/src/generators/application/lib/add-e2e.d.ts +3 -0
- package/src/generators/application/lib/add-e2e.js +72 -0
- package/src/generators/application/lib/add-jest.d.ts +3 -0
- package/src/generators/application/lib/add-jest.js +38 -0
- package/src/generators/application/lib/add-linting.d.ts +3 -0
- package/src/generators/application/lib/add-linting.js +62 -0
- package/src/generators/application/lib/add-plugin.d.ts +2 -0
- package/src/generators/application/lib/add-plugin.js +25 -0
- package/src/generators/application/lib/add-project.d.ts +3 -0
- package/src/generators/application/lib/add-project.js +66 -0
- package/src/generators/application/lib/create-application-files.d.ts +3 -0
- package/src/generators/application/lib/create-application-files.helpers.d.ts +2 -0
- package/src/generators/application/lib/create-application-files.helpers.js +846 -0
- package/src/generators/application/lib/create-application-files.js +114 -0
- package/src/generators/application/lib/normalize-options.d.ts +14 -0
- package/src/generators/application/lib/normalize-options.js +56 -0
- package/src/generators/application/lib/set-defaults.d.ts +3 -0
- package/src/generators/application/lib/set-defaults.js +14 -0
- package/src/generators/application/lib/show-possible-warnings.d.ts +3 -0
- package/src/generators/application/lib/show-possible-warnings.js +10 -0
- package/src/generators/application/lib/update-cypress-tsconfig.d.ts +3 -0
- package/src/generators/application/lib/update-cypress-tsconfig.js +16 -0
- package/src/generators/application/lib/update-jest-config.d.ts +3 -0
- package/src/generators/application/lib/update-jest-config.js +15 -0
- package/src/generators/application/schema.d.ts +24 -0
- package/src/generators/application/schema.json +146 -0
- package/src/generators/component/component.d.ts +28 -0
- package/src/generators/component/component.js +66 -0
- package/src/generators/component/schema.json +125 -0
- package/src/generators/custom-server/custom-server.d.ts +3 -0
- package/src/generators/custom-server/custom-server.js +104 -0
- package/src/generators/custom-server/files/server/main.ts__tmpl__ +46 -0
- package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +17 -0
- package/src/generators/custom-server/schema.d.ts +4 -0
- package/src/generators/custom-server/schema.json +30 -0
- package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +5 -0
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +87 -0
- package/src/generators/cypress-component-configuration/schema.d.ts +6 -0
- package/src/generators/cypress-component-configuration/schema.json +42 -0
- package/src/generators/init/init.d.ts +5 -0
- package/src/generators/init/init.js +46 -0
- package/src/generators/init/lib/add-plugin.d.ts +2 -0
- package/src/generators/init/lib/add-plugin.js +26 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +34 -0
- package/src/generators/library/lib/normalize-options.d.ts +7 -0
- package/src/generators/library/lib/normalize-options.js +26 -0
- package/src/generators/library/library.d.ts +5 -0
- package/src/generators/library/library.js +92 -0
- package/src/generators/library/schema.d.ts +28 -0
- package/src/generators/library/schema.json +156 -0
- package/src/generators/page/page.d.ts +5 -0
- package/src/generators/page/page.js +96 -0
- package/src/generators/page/schema.d.ts +20 -0
- package/src/generators/page/schema.json +111 -0
- package/src/migrations/update-15-8-8/add-style-packages.d.ts +3 -0
- package/src/migrations/update-15-8-8/add-style-packages.js +23 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-3-0/remove-root-build-option.d.ts +2 -0
- package/src/migrations/update-16-3-0/remove-root-build-option.js +17 -0
- package/src/migrations/update-16-4-0/update-nx-next-dependency.d.ts +2 -0
- package/src/migrations/update-16-4-0/update-nx-next-dependency.js +17 -0
- package/src/migrations/update-17-2-7/remove-eslint-rules-patch.d.ts +2 -0
- package/src/migrations/update-17-2-7/remove-eslint-rules-patch.js +15 -0
- package/src/plugins/plugin.d.ts +11 -0
- package/src/plugins/plugin.js +182 -0
- package/src/utils/add-gitignore-entry.d.ts +2 -0
- package/src/utils/add-gitignore-entry.js +17 -0
- package/src/utils/add-swc-to-custom-server.d.ts +2 -0
- package/src/utils/add-swc-to-custom-server.js +37 -0
- package/src/utils/compose-plugins.d.ts +3 -0
- package/src/utils/compose-plugins.js +22 -0
- package/src/utils/config-invalid-function.fixture.d.ts +0 -0
- package/src/utils/config-invalid-function.fixture.js +1 -0
- package/src/utils/config-not-a-function.fixture.d.ts +0 -0
- package/src/utils/config-not-a-function.fixture.js +1 -0
- package/src/utils/config.d.ts +13 -0
- package/src/utils/config.js +24 -0
- package/src/utils/constants.d.ts +1 -0
- package/src/utils/constants.js +4 -0
- package/src/utils/create-cli-options.d.ts +1 -0
- package/src/utils/create-cli-options.js +13 -0
- package/src/utils/create-copy-plugin.d.ts +2 -0
- package/src/utils/create-copy-plugin.js +64 -0
- package/src/utils/generate-globs.d.ts +5 -0
- package/src/utils/generate-globs.js +29 -0
- package/src/utils/styles.d.ts +67 -0
- package/src/utils/styles.js +67 -0
- package/src/utils/types.d.ts +57 -0
- package/src/utils/types.js +2 -0
- package/src/utils/versions.d.ts +12 -0
- package/src/utils/versions.js +15 -0
- package/tailwind.d.ts +2 -0
- package/tailwind.js +6 -0
- package/typings/image.d.ts +12 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "pipe",
|
|
4
|
+
"$schema": "https://json-schema.org/schema",
|
|
5
|
+
"cli": "nx",
|
|
6
|
+
"title": "Next Build",
|
|
7
|
+
"description": "Build a Next.js app.",
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"outputPath": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"description": "The output path of the generated files.",
|
|
13
|
+
"x-completion-type": "directory",
|
|
14
|
+
"x-priority": "important"
|
|
15
|
+
},
|
|
16
|
+
"fileReplacements": {
|
|
17
|
+
"description": "Replace files with other files in the build.",
|
|
18
|
+
"type": "array",
|
|
19
|
+
"items": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {
|
|
22
|
+
"replace": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "The file to be replaced.",
|
|
25
|
+
"x-completion-type": "file"
|
|
26
|
+
},
|
|
27
|
+
"with": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "The file to replace with.",
|
|
30
|
+
"x-completion-type": "file"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"additionalProperties": false,
|
|
34
|
+
"required": ["replace", "with"]
|
|
35
|
+
},
|
|
36
|
+
"default": []
|
|
37
|
+
},
|
|
38
|
+
"nextConfig": {
|
|
39
|
+
"description": "Path (relative to workspace root) to a function which takes phase, config, and builder options, and returns the resulting config. This is an advanced option and should not be used with a normal Next.js config file (i.e. `next.config.js`).",
|
|
40
|
+
"type": "string",
|
|
41
|
+
"x-completion-type": "file",
|
|
42
|
+
"x-completion-glob": "next?(*).js",
|
|
43
|
+
"x-priority": "important"
|
|
44
|
+
},
|
|
45
|
+
"buildLibsFromSource": {
|
|
46
|
+
"type": "boolean",
|
|
47
|
+
"description": "Read buildable libraries from source instead of building them separately.",
|
|
48
|
+
"default": true
|
|
49
|
+
},
|
|
50
|
+
"includeDevDependenciesInPackageJson": {
|
|
51
|
+
"type": "boolean",
|
|
52
|
+
"description": "Include `devDependencies` in the generated package.json file. By default only production `dependencies` are included.",
|
|
53
|
+
"default": false
|
|
54
|
+
},
|
|
55
|
+
"generateLockfile": {
|
|
56
|
+
"type": "boolean",
|
|
57
|
+
"description": "Generate a lockfile (e.g. package-lock.json) that matches the workspace lockfile to ensure package versions match.",
|
|
58
|
+
"default": false,
|
|
59
|
+
"x-priority": "internal"
|
|
60
|
+
},
|
|
61
|
+
"debug": {
|
|
62
|
+
"type": "boolean",
|
|
63
|
+
"description": "Enable Next.js debug build logging"
|
|
64
|
+
},
|
|
65
|
+
"profile": {
|
|
66
|
+
"type": "boolean",
|
|
67
|
+
"description": "Used to enable React Production Profiling"
|
|
68
|
+
},
|
|
69
|
+
"experimentalAppOnly": {
|
|
70
|
+
"type": "boolean",
|
|
71
|
+
"description": "Only build 'app' routes"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"required": ["outputPath"],
|
|
75
|
+
"examplesFile": "../../../docs/build-next-executor-examples.md"
|
|
76
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { NextExportBuilderOptions } from '../../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated use output inside of your next.config.js
|
|
5
|
+
* Example
|
|
6
|
+
* const nextConfig = {
|
|
7
|
+
nx: {
|
|
8
|
+
svgr: false,
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
output: 'export'
|
|
12
|
+
};
|
|
13
|
+
* Read https://nextjs.org/docs/pages/building-your-application/deploying/static-exports
|
|
14
|
+
**/
|
|
15
|
+
export default function exportExecutor(options: NextExportBuilderOptions, context: ExecutorContext): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const export_1 = require("next/dist/export");
|
|
5
|
+
const nextTrace = require("next/dist/trace");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const chalk = require("chalk");
|
|
9
|
+
const semver_1 = require("semver");
|
|
10
|
+
// platform specific command name
|
|
11
|
+
const pmCmd = (0, os_1.platform)() === 'win32' ? `npx.cmd` : 'npx';
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use output inside of your next.config.js
|
|
14
|
+
* Example
|
|
15
|
+
* const nextConfig = {
|
|
16
|
+
nx: {
|
|
17
|
+
svgr: false,
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
output: 'export'
|
|
21
|
+
};
|
|
22
|
+
* Read https://nextjs.org/docs/pages/building-your-application/deploying/static-exports
|
|
23
|
+
**/
|
|
24
|
+
async function exportExecutor(options, context) {
|
|
25
|
+
const nextJsVersion = require('next/package.json').version;
|
|
26
|
+
if ((0, semver_1.satisfies)(nextJsVersion, '>=14.0.0')) {
|
|
27
|
+
throw new Error('The export command has been removed in Next.js 14. Please update your Next config to use the output property. Read more: https://nextjs.org/docs/pages/building-your-application/deploying/static-exports');
|
|
28
|
+
}
|
|
29
|
+
// Returns { project: ProjectGraphNode; target: string; configuration?: string;}
|
|
30
|
+
const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context);
|
|
31
|
+
try {
|
|
32
|
+
const buildTargetName = (0, devkit_1.targetToTargetString)(buildTarget);
|
|
33
|
+
const args = getBuildTargetCommand(buildTargetName);
|
|
34
|
+
(0, child_process_1.execFileSync)(pmCmd, args, {
|
|
35
|
+
stdio: [0, 1, 2],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
throw new Error(`Build target failed: ${chalk.bold(options.buildTarget)}`);
|
|
40
|
+
}
|
|
41
|
+
const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, context);
|
|
42
|
+
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
|
|
43
|
+
// Taken from:
|
|
44
|
+
// https://github.com/vercel/next.js/blob/ead56eaab68409e96c19f7d9139747bac1197aa9/packages/next/cli/next-export.ts#L13
|
|
45
|
+
const nextExportCliSpan = nextTrace.trace('next-export-cli');
|
|
46
|
+
await (0, export_1.default)(projectRoot, {
|
|
47
|
+
statusMessage: 'Exporting',
|
|
48
|
+
silent: options.silent,
|
|
49
|
+
threads: options.threads,
|
|
50
|
+
outdir: `${buildOptions.outputPath}/exported`,
|
|
51
|
+
}, nextExportCliSpan);
|
|
52
|
+
return { success: true };
|
|
53
|
+
}
|
|
54
|
+
exports.default = exportExecutor;
|
|
55
|
+
function getBuildTargetCommand(buildTarget) {
|
|
56
|
+
const cmd = ['nx', 'run', buildTarget];
|
|
57
|
+
return cmd;
|
|
58
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "pipe",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Next Export",
|
|
6
|
+
"description": "Export a Next.js application. The exported application is located at `dist/$outputPath/exported`.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"buildTarget": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Target which builds the application",
|
|
12
|
+
"x-priority": "important"
|
|
13
|
+
},
|
|
14
|
+
"silent": {
|
|
15
|
+
"type": "boolean",
|
|
16
|
+
"description": "Hide progress or not (default is `false`)",
|
|
17
|
+
"default": false
|
|
18
|
+
},
|
|
19
|
+
"threads": {
|
|
20
|
+
"type": "number",
|
|
21
|
+
"description": "Number of worker threads to utilize (defaults to the number of CPUs)"
|
|
22
|
+
},
|
|
23
|
+
"buildLibsFromSource": {
|
|
24
|
+
"type": "boolean",
|
|
25
|
+
"description": "Read buildable libraries from source instead of building them separately.",
|
|
26
|
+
"default": true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"required": []
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { NextServeBuilderOptions } from '../../utils/types';
|
|
3
|
+
export default function serveExecutor(options: NextServeBuilderOptions, context: ExecutorContext): AsyncGenerator<{
|
|
4
|
+
success: boolean;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
}, void, unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
async function* serveExecutor(options, context) {
|
|
6
|
+
// Cast to any to overwrite NODE_ENV
|
|
7
|
+
process.env.NODE_ENV = process.env.NODE_ENV
|
|
8
|
+
? process.env.NODE_ENV
|
|
9
|
+
: options.dev
|
|
10
|
+
? 'development'
|
|
11
|
+
: 'production';
|
|
12
|
+
// Setting port that the custom server should use.
|
|
13
|
+
process.env.PORT = options.port ? `${options.port}` : process.env.PORT;
|
|
14
|
+
options.port = parseInt(process.env.PORT);
|
|
15
|
+
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
|
|
16
|
+
yield* runCustomServer(projectRoot, options, context);
|
|
17
|
+
}
|
|
18
|
+
exports.default = serveExecutor;
|
|
19
|
+
async function* runCustomServer(root, options, context) {
|
|
20
|
+
process.env.NX_NEXT_DIR ??= root;
|
|
21
|
+
process.env.NX_NEXT_PUBLIC_DIR = (0, path_1.join)(root, 'public');
|
|
22
|
+
const baseUrl = `http://${options.hostname || 'localhost'}:${options.port}`;
|
|
23
|
+
const customServerBuild = await (0, devkit_1.runExecutor)((0, devkit_1.parseTargetString)(options.customServerTarget, context), {
|
|
24
|
+
watch: options.dev ? true : false,
|
|
25
|
+
}, context);
|
|
26
|
+
for await (const result of customServerBuild) {
|
|
27
|
+
if (!result.success) {
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
yield {
|
|
31
|
+
success: true,
|
|
32
|
+
baseUrl,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return { success: true };
|
|
36
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "pipe",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Next Serve",
|
|
6
|
+
"description": "Serve a Next.js app.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"dev": {
|
|
10
|
+
"type": "boolean",
|
|
11
|
+
"description": "Serve the application in the dev mode.",
|
|
12
|
+
"default": true
|
|
13
|
+
},
|
|
14
|
+
"buildTarget": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Target which builds the application.",
|
|
17
|
+
"x-priority": "important"
|
|
18
|
+
},
|
|
19
|
+
"port": {
|
|
20
|
+
"type": "number",
|
|
21
|
+
"description": "Port to listen on.",
|
|
22
|
+
"default": 4200,
|
|
23
|
+
"x-priority": "important"
|
|
24
|
+
},
|
|
25
|
+
"staticMarkup": {
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"description": "Static markup.",
|
|
28
|
+
"default": false
|
|
29
|
+
},
|
|
30
|
+
"quiet": {
|
|
31
|
+
"type": "boolean",
|
|
32
|
+
"description": "Hide error messages containing server information.",
|
|
33
|
+
"default": false
|
|
34
|
+
},
|
|
35
|
+
"customServerTarget": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Target which builds the custom server."
|
|
38
|
+
},
|
|
39
|
+
"hostname": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"description": "Hostname on which the application is served."
|
|
42
|
+
},
|
|
43
|
+
"buildLibsFromSource": {
|
|
44
|
+
"type": "boolean",
|
|
45
|
+
"description": "Read buildable libraries from source instead of building them separately.",
|
|
46
|
+
"default": true
|
|
47
|
+
},
|
|
48
|
+
"keepAliveTimeout": {
|
|
49
|
+
"type": "number",
|
|
50
|
+
"description": "Max milliseconds to wait before closing inactive connection."
|
|
51
|
+
},
|
|
52
|
+
"turbo": {
|
|
53
|
+
"type": "boolean",
|
|
54
|
+
"description": "Activate the incremental bundler for Next.js, which is implemented in Rust. Please note, this feature is exclusively available in development mode."
|
|
55
|
+
},
|
|
56
|
+
"experimentalHttps": {
|
|
57
|
+
"type": "boolean",
|
|
58
|
+
"description": "Enable HTTPS support for the Next.js development server."
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"required": ["buildTarget"],
|
|
62
|
+
"examplesFile": "../../../docs/server-next-executor-examples.md"
|
|
63
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { NextServeBuilderOptions } from '../../utils/types';
|
|
3
|
+
export default function serveExecutor(options: NextServeBuilderOptions, context: ExecutorContext): AsyncGenerator<{
|
|
4
|
+
success: boolean;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
}, void, undefined>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const custom_server_impl_1 = require("./custom-server.impl");
|
|
7
|
+
const create_cli_options_1 = require("../../utils/create-cli-options");
|
|
8
|
+
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
9
|
+
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
|
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 = !options.dev && (0, path_1.resolve)(context.root, buildOptions.outputPath);
|
|
15
|
+
process.env.NX_NEXT_DIR ??= options.dev ? projectRoot : nextDir;
|
|
16
|
+
if (options.customServerTarget) {
|
|
17
|
+
return yield* (0, custom_server_impl_1.default)(options, context);
|
|
18
|
+
}
|
|
19
|
+
const { keepAliveTimeout, hostname } = options;
|
|
20
|
+
// Cast to any to overwrite NODE_ENV
|
|
21
|
+
process.env.NODE_ENV = process.env.NODE_ENV
|
|
22
|
+
? process.env.NODE_ENV
|
|
23
|
+
: options.dev
|
|
24
|
+
? 'development'
|
|
25
|
+
: 'production';
|
|
26
|
+
// Setting port that the custom server should use.
|
|
27
|
+
process.env.PORT = options.port ? `${options.port}` : process.env.PORT;
|
|
28
|
+
options.port = parseInt(process.env.PORT);
|
|
29
|
+
const args = (0, create_cli_options_1.createCliOptions)({ port: options.port, hostname });
|
|
30
|
+
if (keepAliveTimeout && !options.dev) {
|
|
31
|
+
args.push(`--keepAliveTimeout=${keepAliveTimeout}`);
|
|
32
|
+
}
|
|
33
|
+
const mode = options.dev ? 'dev' : 'start';
|
|
34
|
+
const turbo = options.turbo && options.dev ? '--turbo' : '';
|
|
35
|
+
const experimentalHttps = options.experimentalHttps && options.dev ? '--experimental-https' : '';
|
|
36
|
+
const nextBin = require.resolve('next/dist/bin/next');
|
|
37
|
+
yield* (0, async_iterable_1.createAsyncIterable)(async ({ done, next, error }) => {
|
|
38
|
+
const server = (0, child_process_1.fork)(nextBin, [mode, ...args, turbo, experimentalHttps], {
|
|
39
|
+
cwd: options.dev ? projectRoot : nextDir,
|
|
40
|
+
stdio: 'inherit',
|
|
41
|
+
});
|
|
42
|
+
server.once('exit', (code) => {
|
|
43
|
+
if (code === 0) {
|
|
44
|
+
done();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
error(new Error(`Next.js app exited with code ${code}`));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const killServer = () => {
|
|
51
|
+
if (server.connected) {
|
|
52
|
+
server.kill('SIGTERM');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
process.on('exit', () => killServer());
|
|
56
|
+
process.on('SIGINT', () => killServer());
|
|
57
|
+
process.on('SIGTERM', () => killServer());
|
|
58
|
+
process.on('SIGHUP', () => killServer());
|
|
59
|
+
await (0, wait_for_port_open_1.waitForPortOpen)(options.port, { host: options.hostname });
|
|
60
|
+
next({
|
|
61
|
+
success: true,
|
|
62
|
+
baseUrl: `http://${options.hostname ?? 'localhost'}:${options.port}`,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.default = serveExecutor;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export declare function applicationGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function applicationGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applicationGeneratorInternal = exports.applicationGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
const versions_1 = require("@nx/react/src/utils/versions");
|
|
7
|
+
const normalize_options_1 = require("./lib/normalize-options");
|
|
8
|
+
const add_e2e_1 = require("./lib/add-e2e");
|
|
9
|
+
const add_jest_1 = require("./lib/add-jest");
|
|
10
|
+
const add_project_1 = require("./lib/add-project");
|
|
11
|
+
const create_application_files_1 = require("./lib/create-application-files");
|
|
12
|
+
const set_defaults_1 = require("./lib/set-defaults");
|
|
13
|
+
const update_jest_config_1 = require("./lib/update-jest-config");
|
|
14
|
+
const init_1 = require("../init/init");
|
|
15
|
+
const styles_1 = require("../../utils/styles");
|
|
16
|
+
const add_linting_1 = require("./lib/add-linting");
|
|
17
|
+
const custom_server_1 = require("../custom-server/custom-server");
|
|
18
|
+
const update_cypress_tsconfig_1 = require("./lib/update-cypress-tsconfig");
|
|
19
|
+
const show_possible_warnings_1 = require("./lib/show-possible-warnings");
|
|
20
|
+
const versions_2 = require("../../utils/versions");
|
|
21
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
22
|
+
async function applicationGenerator(host, schema) {
|
|
23
|
+
return await applicationGeneratorInternal(host, {
|
|
24
|
+
addPlugin: false,
|
|
25
|
+
projectNameAndRootFormat: 'derived',
|
|
26
|
+
...schema,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.applicationGenerator = applicationGenerator;
|
|
30
|
+
async function applicationGeneratorInternal(host, schema) {
|
|
31
|
+
const tasks = [];
|
|
32
|
+
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
33
|
+
(0, show_possible_warnings_1.showPossibleWarnings)(host, options);
|
|
34
|
+
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
35
|
+
js: options.js,
|
|
36
|
+
skipPackageJson: options.skipPackageJson,
|
|
37
|
+
skipFormat: true,
|
|
38
|
+
});
|
|
39
|
+
tasks.push(jsInitTask);
|
|
40
|
+
const nextTask = await (0, init_1.nextInitGenerator)(host, {
|
|
41
|
+
...options,
|
|
42
|
+
skipFormat: true,
|
|
43
|
+
});
|
|
44
|
+
tasks.push(nextTask);
|
|
45
|
+
(0, create_application_files_1.createApplicationFiles)(host, options);
|
|
46
|
+
(0, add_project_1.addProject)(host, options);
|
|
47
|
+
const e2eTask = await (0, add_e2e_1.addE2e)(host, options);
|
|
48
|
+
tasks.push(e2eTask);
|
|
49
|
+
const jestTask = await (0, add_jest_1.addJest)(host, options);
|
|
50
|
+
tasks.push(jestTask);
|
|
51
|
+
const lintTask = await (0, add_linting_1.addLinting)(host, options);
|
|
52
|
+
tasks.push(lintTask);
|
|
53
|
+
const styledTask = (0, styles_1.addStyleDependencies)(host, {
|
|
54
|
+
style: options.style,
|
|
55
|
+
swc: !host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, '.babelrc')),
|
|
56
|
+
});
|
|
57
|
+
tasks.push(styledTask);
|
|
58
|
+
(0, update_jest_config_1.updateJestConfig)(host, options);
|
|
59
|
+
(0, update_cypress_tsconfig_1.updateCypressTsConfig)(host, options);
|
|
60
|
+
(0, set_defaults_1.setDefaults)(host, options);
|
|
61
|
+
if (options.customServer) {
|
|
62
|
+
await (0, custom_server_1.customServerGenerator)(host, {
|
|
63
|
+
project: options.projectName,
|
|
64
|
+
compiler: options.swc ? 'swc' : 'tsc',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (!options.skipPackageJson) {
|
|
68
|
+
const devDependencies = {
|
|
69
|
+
'@types/react': versions_1.typesReactVersion,
|
|
70
|
+
'@types/react-dom': versions_1.typesReactDomVersion,
|
|
71
|
+
};
|
|
72
|
+
if (schema.unitTestRunner && schema.unitTestRunner !== 'none') {
|
|
73
|
+
devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
|
|
74
|
+
}
|
|
75
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { tslib: versions_2.tsLibVersion }, devDependencies));
|
|
76
|
+
}
|
|
77
|
+
if (!options.skipFormat) {
|
|
78
|
+
await (0, devkit_1.formatFiles)(host);
|
|
79
|
+
}
|
|
80
|
+
tasks.push(() => {
|
|
81
|
+
(0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
|
|
82
|
+
});
|
|
83
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
84
|
+
}
|
|
85
|
+
exports.applicationGeneratorInternal = applicationGeneratorInternal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%- styleContent %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%- pageStyleContent %>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<% if (style !== 'none') { %>
|
|
2
|
+
<% if (styledModule && (styledModule === 'styled-jsx' || styledModule === 'styled-components')) {%>
|
|
3
|
+
'use client';
|
|
4
|
+
<% }%>
|
|
5
|
+
<% if (styledModule && styledModule !== 'styled-jsx') {
|
|
6
|
+
var wrapper = 'StyledPage';
|
|
7
|
+
%>import styled from '<%= styledModule %>';<% } else {
|
|
8
|
+
var wrapper = 'div';
|
|
9
|
+
%>
|
|
10
|
+
<%- style !== 'styled-jsx' ? `import styles from './page.module.${style}';` : '' %>
|
|
11
|
+
<% }
|
|
12
|
+
%>
|
|
13
|
+
|
|
14
|
+
<% if (styledModule && styledModule !== 'styled-jsx') { %>
|
|
15
|
+
const StyledPage = styled.div`<%- pageStyleContent %>`;
|
|
16
|
+
<% }%>
|
|
17
|
+
<% } %>
|
|
18
|
+
export default function Index() {
|
|
19
|
+
/*
|
|
20
|
+
* Replace the elements below with your own.
|
|
21
|
+
*
|
|
22
|
+
* Note: The corresponding styles are in the ./<%= fileName %>.<%= style %> file.
|
|
23
|
+
*/
|
|
24
|
+
return (
|
|
25
|
+
<<%= wrapper %><% if (!styledModule) {%> className={styles.page}<% } %>>
|
|
26
|
+
<%- styledModule === 'styled-jsx' && style !== 'none' ? `<style jsx>{\`${pageStyleContent}\`}</style>` : `` %>
|
|
27
|
+
<%- appContent %>
|
|
28
|
+
</<%= wrapper %>>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import './global.<%= stylesExt %>';
|
|
2
|
+
|
|
3
|
+
export const metadata = {
|
|
4
|
+
title: 'Welcome to <%= name %>',
|
|
5
|
+
description: 'Generated by create-nx-workspace',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default function RootLayout({
|
|
9
|
+
children,
|
|
10
|
+
}: {
|
|
11
|
+
children: React.ReactNode
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
<html lang="en">
|
|
15
|
+
<body>{children}</body>
|
|
16
|
+
</html>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import './global.<%= stylesExt %>';
|
|
2
|
+
import { StyledComponentsRegistry } from './registry';
|
|
3
|
+
|
|
4
|
+
export const metadata = {
|
|
5
|
+
title: 'Welcome to demo2',
|
|
6
|
+
description: 'Generated by create-nx-workspace',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default function RootLayout({
|
|
10
|
+
children,
|
|
11
|
+
}: {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}) {
|
|
14
|
+
return (
|
|
15
|
+
<html lang="en">
|
|
16
|
+
<body>
|
|
17
|
+
<StyledComponentsRegistry>{children}</StyledComponentsRegistry>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
|
+
import { useServerInsertedHTML } from 'next/navigation';
|
|
5
|
+
import { ServerStyleSheet, StyleSheetManager } from 'styled-components';
|
|
6
|
+
|
|
7
|
+
export function StyledComponentsRegistry({
|
|
8
|
+
children,
|
|
9
|
+
}: {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}) {
|
|
12
|
+
// Only create stylesheet once with lazy initial state
|
|
13
|
+
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
|
|
14
|
+
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());
|
|
15
|
+
|
|
16
|
+
useServerInsertedHTML(() => {
|
|
17
|
+
const styles = styledComponentsStyleSheet.getStyleElement();
|
|
18
|
+
|
|
19
|
+
// Types are out of date, clearTag is not defined.
|
|
20
|
+
// See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/65021
|
|
21
|
+
(styledComponentsStyleSheet.instance as any).clearTag();
|
|
22
|
+
|
|
23
|
+
return <>{styles}</>;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (typeof window !== 'undefined') return <>{children}</>;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
|
|
30
|
+
{children}
|
|
31
|
+
</StyleSheetManager>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import './global.<%= stylesExt %>';
|
|
2
|
+
import { StyledJsxRegistry } from './registry';
|
|
3
|
+
|
|
4
|
+
export default function RootLayout({
|
|
5
|
+
children,
|
|
6
|
+
}: {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}) {
|
|
9
|
+
return (
|
|
10
|
+
<html>
|
|
11
|
+
<body>
|
|
12
|
+
<StyledJsxRegistry>{children}</StyledJsxRegistry>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
|
+
import { useServerInsertedHTML } from 'next/navigation';
|
|
5
|
+
import { StyleRegistry, createStyleRegistry } from 'styled-jsx';
|
|
6
|
+
|
|
7
|
+
export function StyledJsxRegistry({
|
|
8
|
+
children,
|
|
9
|
+
}: {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}) {
|
|
12
|
+
// Only create stylesheet once with lazy initial state
|
|
13
|
+
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
|
|
14
|
+
const [jsxStyleRegistry] = useState(() => createStyleRegistry());
|
|
15
|
+
|
|
16
|
+
useServerInsertedHTML(() => {
|
|
17
|
+
const styles = jsxStyleRegistry.styles();
|
|
18
|
+
jsxStyleRegistry.flush();
|
|
19
|
+
return <>{styles}</>;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return <StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"presets": [
|
|
3
|
+
<% if (style === '@emotion/styled') { %>
|
|
4
|
+
[
|
|
5
|
+
"@nx/next/babel",
|
|
6
|
+
{
|
|
7
|
+
"preset-react": {
|
|
8
|
+
"runtime": "automatic",
|
|
9
|
+
"importSource": "@emotion/react"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
<% } else { %>
|
|
14
|
+
"@nx/next/babel"
|
|
15
|
+
<% } %>
|
|
16
|
+
],
|
|
17
|
+
"plugins": [
|
|
18
|
+
<% if (style === '@emotion/styled') { %>"@emotion/babel-plugin"<% } %>
|
|
19
|
+
<% if (style === 'styled-components') { %>["styled-components", { "pure": true, "ssr": true }]<% } %>
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
declare module '*.svg' {
|
|
3
|
+
const content: any;
|
|
4
|
+
export const ReactComponent: any;
|
|
5
|
+
export default content;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
<% if (style === 'less') { %>
|
|
9
|
+
declare module '*.module.less' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
<% } %>
|