@nx/next 17.0.2 → 17.0.4
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 +1 -1
- package/README.md +9 -4
- package/generators.json +2 -2
- package/migrations.json +24 -0
- package/package.json +12 -10
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/plugins/component-testing.d.ts +1 -11
- package/plugins/component-testing.js +26 -10
- package/plugins/with-nx.d.ts +1 -1
- package/plugins/with-nx.js +68 -86
- package/plugins/with-stylus.js +1 -1
- package/src/executors/build/build.impl.js +20 -9
- package/src/executors/build/lib/create-next-config-file.js +5 -2
- package/src/executors/build/lib/test-fixtures/ensure-exts/baz.json +1 -0
- package/src/executors/build/lib/update-package-json.js +10 -1
- package/src/executors/build/schema.json +1 -1
- package/src/executors/export/export.impl.js +9 -9
- package/src/executors/server/custom-server.impl.js +3 -2
- package/src/executors/server/schema.json +4 -0
- package/src/executors/server/server.impl.js +13 -11
- package/src/generators/application/application.js +24 -0
- package/src/generators/application/files/app/page.tsx__tmpl__ +1 -1
- package/src/generators/application/files/common/specs/__fileName__.spec.tsx__tmpl__ +10 -3
- package/src/generators/application/files/common/tsconfig.json__tmpl__ +5 -5
- package/src/generators/application/files/pages/__fileName__.tsx__tmpl__ +1 -1
- package/src/generators/application/lib/add-e2e.js +27 -3
- package/src/generators/application/lib/add-linting.js +13 -16
- 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.js +43 -33
- package/src/generators/application/lib/create-application-files.helpers.js +67 -5
- package/src/generators/application/lib/create-application-files.js +23 -11
- package/src/generators/application/lib/normalize-options.d.ts +3 -0
- package/src/generators/application/lib/normalize-options.js +31 -0
- package/src/generators/application/schema.d.ts +2 -0
- package/src/generators/application/schema.json +9 -3
- package/src/generators/component/component.d.ts +4 -4
- package/src/generators/component/component.js +3 -2
- package/src/generators/component/schema.json +7 -7
- package/src/generators/custom-server/custom-server.d.ts +1 -1
- package/src/generators/custom-server/custom-server.js +34 -9
- package/src/generators/custom-server/files/server/main.ts__tmpl__ +4 -4
- package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +2 -0
- package/src/generators/custom-server/schema.json +1 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +1 -0
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +23 -10
- package/src/generators/cypress-component-configuration/schema.d.ts +1 -0
- package/src/generators/cypress-component-configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +4 -3
- package/src/generators/init/init.js +30 -44
- 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 +3 -4
- package/src/generators/init/schema.json +11 -23
- package/src/generators/library/lib/normalize-options.js +5 -0
- package/src/generators/library/library.js +19 -1
- package/src/generators/library/schema.d.ts +2 -1
- package/src/generators/library/schema.json +3 -3
- package/src/generators/page/page.js +21 -4
- package/src/generators/page/schema.d.ts +3 -3
- package/src/generators/page/schema.json +5 -5
- 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 +184 -0
- package/src/utils/add-gitignore-entry.js +1 -1
- 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/styles.d.ts +4 -4
- package/src/utils/types.d.ts +1 -0
- package/src/utils/versions.d.ts +6 -2
- package/src/utils/versions.js +7 -3
|
@@ -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;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export interface InitSchema {
|
|
2
|
-
unitTestRunner?: 'jest' | 'none';
|
|
3
|
-
e2eTestRunner?: 'cypress' | 'playwright' | 'none';
|
|
4
2
|
skipFormat?: boolean;
|
|
5
|
-
js?: boolean;
|
|
6
3
|
skipPackageJson?: boolean;
|
|
7
|
-
|
|
4
|
+
keepExistingVersions?: boolean;
|
|
5
|
+
updatePackageScripts?: boolean;
|
|
6
|
+
addPlugin?: boolean;
|
|
8
7
|
}
|
|
@@ -1,45 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "NxNextNgInit",
|
|
5
5
|
"title": "Init Next Plugin",
|
|
6
6
|
"description": "Init Next Plugin.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
|
-
"unitTestRunner": {
|
|
10
|
-
"description": "Adds the specified unit test runner.",
|
|
11
|
-
"type": "string",
|
|
12
|
-
"enum": ["jest", "none"],
|
|
13
|
-
"default": "jest"
|
|
14
|
-
},
|
|
15
|
-
"e2eTestRunner": {
|
|
16
|
-
"description": "Adds the specified e2e test runner.",
|
|
17
|
-
"type": "string",
|
|
18
|
-
"enum": ["cypress", "none"],
|
|
19
|
-
"default": "cypress"
|
|
20
|
-
},
|
|
21
9
|
"skipFormat": {
|
|
22
10
|
"description": "Skip formatting files.",
|
|
23
11
|
"type": "boolean",
|
|
24
12
|
"default": false
|
|
25
13
|
},
|
|
26
|
-
"js": {
|
|
27
|
-
"type": "boolean",
|
|
28
|
-
"default": false,
|
|
29
|
-
"description": "Use JavaScript instead of TypeScript"
|
|
30
|
-
},
|
|
31
14
|
"skipPackageJson": {
|
|
32
15
|
"type": "boolean",
|
|
33
16
|
"default": false,
|
|
34
17
|
"description": "Do not add dependencies to `package.json`.",
|
|
35
18
|
"x-priority": "internal"
|
|
36
19
|
},
|
|
37
|
-
"
|
|
38
|
-
"description": "Create an application at the root of the workspace.",
|
|
20
|
+
"keepExistingVersions": {
|
|
39
21
|
"type": "boolean",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
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
|
|
43
31
|
}
|
|
44
32
|
},
|
|
45
33
|
"required": []
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
5
6
|
async function normalizeOptions(host, options) {
|
|
6
7
|
const { projectRoot, importPath, projectNameAndRootFormat } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
@@ -12,6 +13,10 @@ async function normalizeOptions(host, options) {
|
|
|
12
13
|
callingGenerator: '@nx/next:library',
|
|
13
14
|
});
|
|
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;
|
|
15
20
|
return {
|
|
16
21
|
...options,
|
|
17
22
|
importPath,
|
|
@@ -4,10 +4,13 @@ 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");
|
|
7
8
|
const init_1 = require("../init/init");
|
|
8
9
|
const normalize_options_1 = require("./lib/normalize-options");
|
|
10
|
+
const versions_2 = require("../../utils/versions");
|
|
9
11
|
async function libraryGenerator(host, rawOptions) {
|
|
10
12
|
return await libraryGeneratorInternal(host, {
|
|
13
|
+
addPlugin: false,
|
|
11
14
|
projectNameAndRootFormat: 'derived',
|
|
12
15
|
...rawOptions,
|
|
13
16
|
});
|
|
@@ -16,9 +19,14 @@ exports.libraryGenerator = libraryGenerator;
|
|
|
16
19
|
async function libraryGeneratorInternal(host, rawOptions) {
|
|
17
20
|
const options = await (0, normalize_options_1.normalizeOptions)(host, rawOptions);
|
|
18
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);
|
|
19
28
|
const initTask = await (0, init_1.nextInitGenerator)(host, {
|
|
20
29
|
...options,
|
|
21
|
-
e2eTestRunner: 'none',
|
|
22
30
|
skipFormat: true,
|
|
23
31
|
});
|
|
24
32
|
tasks.push(initTask);
|
|
@@ -28,6 +36,16 @@ async function libraryGeneratorInternal(host, rawOptions) {
|
|
|
28
36
|
skipFormat: true,
|
|
29
37
|
});
|
|
30
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
|
+
}
|
|
31
49
|
const indexPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src', `index.${options.js ? 'js' : 'ts'}`);
|
|
32
50
|
const indexContent = host.read(indexPath, 'utf-8');
|
|
33
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}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
2
|
import type { Linter } from '@nx/eslint';
|
|
3
3
|
import type { SupportedStyles } from '@nx/react';
|
|
4
4
|
|
|
@@ -24,4 +24,5 @@ export interface Schema {
|
|
|
24
24
|
strict?: boolean;
|
|
25
25
|
setParserOptionsProject?: boolean;
|
|
26
26
|
skipPackageJson?: boolean;
|
|
27
|
+
addPlugin?: boolean;
|
|
27
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://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) [
|
|
43
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"value": "less",
|
|
47
|
-
"label": "LESS [
|
|
47
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
"value": "styled-components",
|
|
@@ -21,7 +21,8 @@ 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
|
-
|
|
24
|
+
isNextPage: true,
|
|
25
|
+
nameAndDirectoryFormat: 'as-provided', // already determined the directory so use as is
|
|
25
26
|
export: false,
|
|
26
27
|
classComponent: false,
|
|
27
28
|
routing: false,
|
|
@@ -42,18 +43,34 @@ exports.pageGeneratorInternal = pageGeneratorInternal;
|
|
|
42
43
|
async function normalizeOptions(host, options) {
|
|
43
44
|
let isAppRouter;
|
|
44
45
|
let derivedDirectory;
|
|
46
|
+
let routerDirectory;
|
|
45
47
|
if (options.project) {
|
|
46
48
|
// Legacy behavior, detect app vs page router from specified project.
|
|
47
|
-
// TODO(
|
|
49
|
+
// TODO(v19): remove this logic
|
|
48
50
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
49
51
|
// app/ is a reserved folder in nextjs so it is safe to check it's existence
|
|
50
|
-
isAppRouter =
|
|
51
|
-
|
|
52
|
+
isAppRouter =
|
|
53
|
+
host.exists(`${project.root}/app`) ||
|
|
54
|
+
host.exists(`${project.root}/src/app`);
|
|
55
|
+
routerDirectory = isAppRouter ? 'app' : 'pages';
|
|
52
56
|
derivedDirectory = options.directory
|
|
53
57
|
? `${routerDirectory}/${options.directory}`
|
|
54
58
|
: `${routerDirectory}`;
|
|
55
59
|
}
|
|
56
60
|
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';
|
|
57
74
|
// New behavior, use directory as is without detecting whether we're using app or pages router.
|
|
58
75
|
derivedDirectory = options.directory;
|
|
59
76
|
}
|
|
@@ -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
|
|
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.
|
|
7
7
|
*/
|
|
8
|
-
project
|
|
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
|
|
15
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
16
16
|
*/
|
|
17
17
|
flat?: boolean;
|
|
18
18
|
skipFormat?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://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
|
|
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."
|
|
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) [
|
|
54
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
"value": "less",
|
|
58
|
-
"label": "LESS [
|
|
58
|
+
"label": "LESS [ https://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
|
|
100
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19."
|
|
101
101
|
},
|
|
102
102
|
"skipFormat": {
|
|
103
103
|
"description": "Skip formatting files.",
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
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>;
|
|
@@ -0,0 +1,184 @@
|
|
|
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;
|
|
@@ -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\n`;
|
|
13
|
+
content = `${content}\n\n# Next.js\n.next\nout\n`;
|
|
14
14
|
}
|
|
15
15
|
host.write('.gitignore', content);
|
|
16
16
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
}
|
package/src/utils/styles.d.ts
CHANGED
|
@@ -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("
|
|
4
|
+
dependencies: import("@nx/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("
|
|
13
|
+
devDependencies: import("@nx/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("
|
|
35
|
+
dependencies: import("@nx/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("
|
|
44
|
+
devDependencies: import("@nx/react/src/utils/dependencies").DependencyEntries;
|
|
45
45
|
};
|
|
46
46
|
css: {
|
|
47
47
|
dependencies: {};
|
package/src/utils/types.d.ts
CHANGED
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
|
-
export declare const nextVersion = "
|
|
3
|
-
export declare const eslintConfigNextVersion = "
|
|
2
|
+
export declare const nextVersion = "14.0.4";
|
|
3
|
+
export declare const eslintConfigNextVersion = "14.0.4";
|
|
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";
|
package/src/utils/versions.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.emotionServerVersion = exports.lessLoader = exports.sassVersion = exports.eslintConfigNextVersion = exports.nextVersion = exports.nxVersion = void 0;
|
|
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;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
|
-
exports.nextVersion = '
|
|
6
|
-
exports.eslintConfigNextVersion = '
|
|
5
|
+
exports.nextVersion = '14.0.4';
|
|
6
|
+
exports.eslintConfigNextVersion = '14.0.4';
|
|
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';
|