@nx/next 16.8.0-beta.4 → 16.8.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -9
- package/plugins/component-testing.js +14 -8
- package/plugins/with-less.js +19 -14
- package/plugins/with-nx.js +27 -28
- package/plugins/with-stylus.js +18 -14
- package/src/executors/build/build.impl.js +60 -66
- package/src/executors/build/lib/create-next-config-file.js +2 -4
- package/src/executors/build/lib/update-package-json.js +2 -4
- package/src/executors/export/export.impl.js +29 -32
- package/src/executors/server/custom-server.impl.js +27 -45
- package/src/executors/server/server.impl.js +52 -56
- package/src/generators/application/application.js +38 -37
- package/src/generators/application/lib/add-e2e.js +35 -31
- package/src/generators/application/lib/add-jest.js +29 -26
- package/src/generators/application/lib/add-linting.js +50 -47
- package/src/generators/application/lib/add-project.js +3 -1
- package/src/generators/application/lib/create-application-files.js +26 -8
- package/src/generators/application/lib/normalize-options.js +40 -33
- package/src/generators/application/lib/set-defaults.js +5 -7
- package/src/generators/application/lib/update-cypress-tsconfig.js +4 -1
- package/src/generators/component/component.js +16 -13
- package/src/generators/custom-server/custom-server.js +68 -69
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +55 -57
- package/src/generators/init/init.js +36 -33
- package/src/generators/library/lib/normalize-options.js +14 -14
- package/src/generators/library/library.js +52 -47
- package/src/generators/page/page.js +21 -14
- package/src/migrations/update-12-10-0/fix-page-dir-for-eslint.js +23 -24
- package/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.js +13 -16
- package/src/migrations/update-13-0-0/update-emotion-setup.js +24 -27
- package/src/migrations/update-13-0-0/update-to-webpack-5.js +20 -23
- package/src/migrations/update-13-0-3/fix-less.js +15 -18
- package/src/migrations/update-13-1-1/enable-swc.js +28 -32
- package/src/migrations/update-14-0-0/add-default-development-configurations.js +22 -27
- package/src/migrations/update-14-4-3/add-dev-output-path.js +11 -15
- package/src/migrations/update-14-5-3/add-gitignore-entry.js +3 -6
- package/src/migrations/update-14-5-3/update-dev-output-path.js +14 -19
- package/src/migrations/update-14-5-7/update-next-eslint.js +18 -22
- package/src/migrations/update-15-8-8/add-style-packages.js +14 -18
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-3-0/remove-root-build-option.js +10 -13
- package/src/migrations/update-16-4-0/update-nx-next-dependency.js +12 -15
- package/src/utils/compose-plugins.js +12 -15
- package/src/utils/create-copy-plugin.js +6 -4
- package/src/utils/generate-globs.js +1 -1
- package/src/utils/styles.js +31 -11
|
@@ -49,6 +49,8 @@ function addProject(host, options) {
|
|
|
49
49
|
targets,
|
|
50
50
|
tags: options.parsedTags,
|
|
51
51
|
};
|
|
52
|
-
(0, devkit_1.addProjectConfiguration)(host, options.projectName,
|
|
52
|
+
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
|
53
|
+
...project,
|
|
54
|
+
});
|
|
53
55
|
}
|
|
54
56
|
exports.addProject = addProject;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createApplicationFiles = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const path_1 = require("path");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const js_1 = require("@nx/js");
|
|
@@ -10,11 +9,22 @@ function createApplicationFiles(host, options) {
|
|
|
10
9
|
const offsetFromRoot = (0, devkit_1.offsetFromRoot)(options.appProjectRoot);
|
|
11
10
|
const layoutTypeSrcPath = (0, devkit_1.joinPathFragments)(offsetFromRoot, options.appProjectRoot, '.next/types/**/*.ts');
|
|
12
11
|
const layoutTypeDistPath = (0, devkit_1.joinPathFragments)(offsetFromRoot, options.outputPath, '.next/types/**/*.ts');
|
|
13
|
-
const templateVariables =
|
|
12
|
+
const templateVariables = {
|
|
13
|
+
...(0, devkit_1.names)(options.name),
|
|
14
|
+
...options,
|
|
15
|
+
dot: '.',
|
|
16
|
+
tmpl: '',
|
|
17
|
+
offsetFromRoot,
|
|
14
18
|
layoutTypeSrcPath,
|
|
15
|
-
layoutTypeDistPath,
|
|
19
|
+
layoutTypeDistPath,
|
|
20
|
+
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot),
|
|
21
|
+
appContent: (0, create_application_files_helpers_1.createAppJsx)(options.projectName),
|
|
22
|
+
styleContent: (0, create_application_files_helpers_1.createStyleRules)(),
|
|
23
|
+
pageStyleContent: `.page {}`,
|
|
24
|
+
stylesExt: options.style === 'less' || options.style === 'styl'
|
|
16
25
|
? options.style
|
|
17
|
-
: 'css'
|
|
26
|
+
: 'css',
|
|
27
|
+
};
|
|
18
28
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/common'), options.appProjectRoot, templateVariables);
|
|
19
29
|
if (options.appDir) {
|
|
20
30
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app'), (0, path_1.join)(options.appProjectRoot, 'app'), templateVariables);
|
|
@@ -36,23 +46,31 @@ function createApplicationFiles(host, options) {
|
|
|
36
46
|
if (options.rootProject) {
|
|
37
47
|
(0, devkit_1.updateJson)(host, 'tsconfig.base.json', (json) => {
|
|
38
48
|
const appJSON = (0, devkit_1.readJson)(host, 'tsconfig.json');
|
|
39
|
-
let { extends: _
|
|
49
|
+
let { extends: _, ...updatedJson } = json;
|
|
40
50
|
// Don't generate the `paths` object or else workspace libs will not work later.
|
|
41
51
|
// It'll be generated as needed when a lib is first added.
|
|
42
52
|
delete json.compilerOptions.paths;
|
|
43
|
-
updatedJson =
|
|
53
|
+
updatedJson = {
|
|
54
|
+
...devkit_1.updateJson,
|
|
55
|
+
compilerOptions: {
|
|
56
|
+
...updatedJson.compilerOptions,
|
|
57
|
+
...appJSON.compilerOptions,
|
|
58
|
+
},
|
|
59
|
+
include: [
|
|
44
60
|
...new Set([
|
|
45
61
|
...(updatedJson.include || []),
|
|
46
62
|
...(appJSON.include || []),
|
|
47
63
|
]),
|
|
48
|
-
],
|
|
64
|
+
],
|
|
65
|
+
exclude: [
|
|
49
66
|
...new Set([
|
|
50
67
|
...(updatedJson.exclude || []),
|
|
51
68
|
...(appJSON.exclude || []),
|
|
52
69
|
'**e2e/**/*',
|
|
53
70
|
`dist/${options.projectName}/**/*`,
|
|
54
71
|
]),
|
|
55
|
-
]
|
|
72
|
+
],
|
|
73
|
+
};
|
|
56
74
|
return updatedJson;
|
|
57
75
|
});
|
|
58
76
|
host.delete('tsconfig.json');
|
|
@@ -1,43 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeOptions = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
7
6
|
const linter_1 = require("@nx/linter");
|
|
8
7
|
const assertion_1 = require("@nx/react/src/utils/assertion");
|
|
9
|
-
function normalizeOptions(host, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
rootProject: options.rootProject,
|
|
18
|
-
callingGenerator: '@nx/next:application',
|
|
19
|
-
});
|
|
20
|
-
options.rootProject = appProjectRoot === '.';
|
|
21
|
-
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
22
|
-
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
|
23
|
-
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
|
24
|
-
const name = (0, devkit_1.names)(options.name).fileName;
|
|
25
|
-
const outputPath = (0, devkit_1.joinPathFragments)('dist', appProjectRoot, ...(options.rootProject ? [name] : []));
|
|
26
|
-
const parsedTags = options.tags
|
|
27
|
-
? options.tags.split(',').map((s) => s.trim())
|
|
28
|
-
: [];
|
|
29
|
-
const fileName = 'index';
|
|
30
|
-
const appDir = (_a = options.appDir) !== null && _a !== void 0 ? _a : true;
|
|
31
|
-
const styledModule = /^(css|scss|less|styl)$/.test(options.style)
|
|
32
|
-
? null
|
|
33
|
-
: options.style;
|
|
34
|
-
(0, assertion_1.assertValidStyle)(options.style);
|
|
35
|
-
return Object.assign(Object.assign({}, options), { appDir,
|
|
36
|
-
appProjectRoot,
|
|
37
|
-
e2eProjectName,
|
|
38
|
-
e2eProjectRoot, e2eTestRunner: options.e2eTestRunner || 'cypress', fileName, linter: options.linter || linter_1.Linter.EsLint, name,
|
|
39
|
-
outputPath,
|
|
40
|
-
parsedTags, projectName: appProjectName, style: options.style || 'css', styledModule, unitTestRunner: options.unitTestRunner || 'jest' });
|
|
8
|
+
async function normalizeOptions(host, options) {
|
|
9
|
+
const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
10
|
+
name: options.name,
|
|
11
|
+
projectType: 'application',
|
|
12
|
+
directory: options.directory,
|
|
13
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
14
|
+
rootProject: options.rootProject,
|
|
15
|
+
callingGenerator: '@nx/next:application',
|
|
41
16
|
});
|
|
17
|
+
options.rootProject = appProjectRoot === '.';
|
|
18
|
+
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
19
|
+
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
|
20
|
+
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
|
21
|
+
const name = (0, devkit_1.names)(options.name).fileName;
|
|
22
|
+
const outputPath = (0, devkit_1.joinPathFragments)('dist', appProjectRoot, ...(options.rootProject ? [name] : []));
|
|
23
|
+
const parsedTags = options.tags
|
|
24
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
25
|
+
: [];
|
|
26
|
+
const fileName = 'index';
|
|
27
|
+
const appDir = options.appDir ?? true;
|
|
28
|
+
const styledModule = /^(css|scss|less|styl)$/.test(options.style)
|
|
29
|
+
? null
|
|
30
|
+
: options.style;
|
|
31
|
+
(0, assertion_1.assertValidStyle)(options.style);
|
|
32
|
+
return {
|
|
33
|
+
...options,
|
|
34
|
+
appDir,
|
|
35
|
+
appProjectRoot,
|
|
36
|
+
e2eProjectName,
|
|
37
|
+
e2eProjectRoot,
|
|
38
|
+
e2eTestRunner: options.e2eTestRunner || 'cypress',
|
|
39
|
+
fileName,
|
|
40
|
+
linter: options.linter || linter_1.Linter.EsLint,
|
|
41
|
+
name,
|
|
42
|
+
outputPath,
|
|
43
|
+
parsedTags,
|
|
44
|
+
projectName: appProjectName,
|
|
45
|
+
style: options.style || 'css',
|
|
46
|
+
styledModule,
|
|
47
|
+
unitTestRunner: options.unitTestRunner || 'jest',
|
|
48
|
+
};
|
|
42
49
|
}
|
|
43
50
|
exports.normalizeOptions = normalizeOptions;
|
|
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setDefaults = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
function setDefaults(host, options) {
|
|
6
|
-
var _a, _b, _c, _d, _e;
|
|
7
|
-
var _f, _g, _h, _j;
|
|
8
6
|
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
nxJson.generators ??= {};
|
|
8
|
+
nxJson.generators['@nx/next'] ??= {};
|
|
9
|
+
nxJson.generators['@nx/next'].application ??= {};
|
|
10
|
+
nxJson.generators['@nx/next'].application.style ??= options.style;
|
|
11
|
+
nxJson.generators['@nx/next'].application.linter ??= options.linter;
|
|
14
12
|
(0, devkit_1.updateNxJson)(host, nxJson);
|
|
15
13
|
}
|
|
16
14
|
exports.setDefaults = setDefaults;
|
|
@@ -7,7 +7,10 @@ function updateCypressTsConfig(host, options) {
|
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
(0, devkit_1.updateJson)(host, `${options.e2eProjectRoot}/tsconfig.json`, (json) => {
|
|
10
|
-
return
|
|
10
|
+
return {
|
|
11
|
+
...json,
|
|
12
|
+
exclude: [],
|
|
13
|
+
};
|
|
11
14
|
});
|
|
12
15
|
}
|
|
13
16
|
exports.updateCypressTsConfig = updateCypressTsConfig;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentSchematic = exports.componentGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const react_1 = require("@nx/react");
|
|
7
6
|
const styles_1 = require("../../utils/styles");
|
|
@@ -18,19 +17,23 @@ function getDirectory(host, options) {
|
|
|
18
17
|
* This schematic is basically the React one, but for Next we need
|
|
19
18
|
* extra dependencies for css, sass, less, styl style options.
|
|
20
19
|
*/
|
|
21
|
-
function componentGenerator(host, options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (!options.skipFormat) {
|
|
30
|
-
yield (0, devkit_1.formatFiles)(host);
|
|
31
|
-
}
|
|
32
|
-
return (0, devkit_1.runTasksInSerial)(styledInstall, componentInstall);
|
|
20
|
+
async function componentGenerator(host, options) {
|
|
21
|
+
const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
22
|
+
const componentInstall = await (0, react_1.componentGenerator)(host, {
|
|
23
|
+
...options,
|
|
24
|
+
directory: getDirectory(host, options),
|
|
25
|
+
classComponent: false,
|
|
26
|
+
routing: false,
|
|
27
|
+
skipFormat: true,
|
|
33
28
|
});
|
|
29
|
+
const styledInstall = (0, styles_1.addStyleDependencies)(host, {
|
|
30
|
+
style: options.style,
|
|
31
|
+
swc: !host.exists((0, devkit_1.joinPathFragments)(project.root, '.babelrc')),
|
|
32
|
+
});
|
|
33
|
+
if (!options.skipFormat) {
|
|
34
|
+
await (0, devkit_1.formatFiles)(host);
|
|
35
|
+
}
|
|
36
|
+
return (0, devkit_1.runTasksInSerial)(styledInstall, componentInstall);
|
|
34
37
|
}
|
|
35
38
|
exports.componentGenerator = componentGenerator;
|
|
36
39
|
exports.default = componentGenerator;
|
|
@@ -1,79 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.customServerSchematic = exports.customServerGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const path_1 = require("path");
|
|
7
|
-
function customServerGenerator(host, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
project.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
6
|
+
async function customServerGenerator(host, options) {
|
|
7
|
+
const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
8
|
+
if (project.targets?.build?.executor !== '@nx/next:build' &&
|
|
9
|
+
project.targets?.build?.executor !== '@nrwl/next:build') {
|
|
10
|
+
devkit_1.logger.error(`Project ${options.project} is not a Next.js project. Did you generate it with "nx g @nx/next:app"?`);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const outputPath = project.targets?.build?.options?.outputPath;
|
|
14
|
+
const root = project.root;
|
|
15
|
+
if (!root ||
|
|
16
|
+
!outputPath ||
|
|
17
|
+
!project.targets?.build?.configurations?.development ||
|
|
18
|
+
!project.targets?.build?.configurations?.production) {
|
|
19
|
+
devkit_1.logger.error(`Project ${options.project} has invalid config. Did you generate it with "nx g @nx/next:app"?`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (project.targets?.['build-custom-server'] ||
|
|
23
|
+
project.targets?.['serve-custom-server']) {
|
|
24
|
+
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.`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files'), project.root, {
|
|
28
|
+
...options,
|
|
29
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(project.root),
|
|
30
|
+
projectRoot: project.root,
|
|
31
|
+
tmpl: '',
|
|
32
|
+
});
|
|
33
|
+
project.targets.build.dependsOn = ['build-custom-server'];
|
|
34
|
+
project.targets.serve.options.customServerTarget = `${options.project}:serve-custom-server`;
|
|
35
|
+
project.targets.serve.configurations.development.customServerTarget = `${options.project}:serve-custom-server:development`;
|
|
36
|
+
project.targets.serve.configurations.production.customServerTarget = `${options.project}:serve-custom-server:production`;
|
|
37
|
+
project.targets['build-custom-server'] = {
|
|
38
|
+
executor: '@nx/js:tsc',
|
|
39
|
+
defaultConfiguration: 'production',
|
|
40
|
+
options: {
|
|
41
|
+
outputPath,
|
|
42
|
+
main: `${root}/server/main.ts`,
|
|
43
|
+
tsConfig: `${root}/tsconfig.server.json`,
|
|
44
|
+
clean: false,
|
|
45
|
+
assets: [],
|
|
46
|
+
},
|
|
47
|
+
configurations: {
|
|
48
|
+
development: {},
|
|
49
|
+
production: {},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
project.targets['serve-custom-server'] = {
|
|
53
|
+
executor: '@nx/js:node',
|
|
54
|
+
defaultConfiguration: 'development',
|
|
55
|
+
options: {
|
|
56
|
+
buildTarget: `${options.project}:build-custom-server`,
|
|
57
|
+
},
|
|
58
|
+
configurations: {
|
|
59
|
+
development: {
|
|
60
|
+
buildTarget: `${options.project}:build-custom-server:development`,
|
|
55
61
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
buildTarget: `${options.project}:build-custom-server:development`,
|
|
59
|
-
},
|
|
60
|
-
production: {
|
|
61
|
-
buildTarget: `${options.project}:build-custom-server:production`,
|
|
62
|
-
},
|
|
62
|
+
production: {
|
|
63
|
+
buildTarget: `${options.project}:build-custom-server:production`,
|
|
63
64
|
},
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
json.tasksRunnerOptions.default.options.cacheableOperations
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return json;
|
|
76
|
-
});
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.project, project);
|
|
68
|
+
(0, devkit_1.updateJson)(host, 'nx.json', (json) => {
|
|
69
|
+
json.tasksRunnerOptions ??= {};
|
|
70
|
+
json.tasksRunnerOptions.default ??= { options: {} };
|
|
71
|
+
json.tasksRunnerOptions.default.options.cacheableOperations = [
|
|
72
|
+
...json.tasksRunnerOptions.default.options.cacheableOperations,
|
|
73
|
+
'build-custom-server',
|
|
74
|
+
];
|
|
75
|
+
return json;
|
|
77
76
|
});
|
|
78
77
|
}
|
|
79
78
|
exports.customServerGenerator = customServerGenerator;
|
|
@@ -1,75 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cypressComponentConfiguration = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const ct_utils_1 = require("@nx/react/src/utils/ct-utils");
|
|
7
6
|
const versions_1 = require("../../utils/versions");
|
|
8
7
|
const react_1 = require("@nx/react");
|
|
9
8
|
const path_1 = require("path");
|
|
10
|
-
function cypressComponentConfiguration(tree, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
projectConfig.targets['component-test'].options
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
9
|
+
async function cypressComponentConfiguration(tree, options) {
|
|
10
|
+
const tasks = [];
|
|
11
|
+
const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
12
|
+
tasks.push(await baseCyCtConfig(tree, {
|
|
13
|
+
project: options.project,
|
|
14
|
+
skipFormat: true,
|
|
15
|
+
}));
|
|
16
|
+
const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
|
|
17
|
+
tasks.push(await webpackInitGenerator(tree, {
|
|
18
|
+
compiler: 'swc',
|
|
19
|
+
uiFramework: 'react',
|
|
20
|
+
skipFormat: true,
|
|
21
|
+
}));
|
|
22
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
23
|
+
projectConfig.targets['component-test'].options = {
|
|
24
|
+
...projectConfig.targets['component-test'].options,
|
|
25
|
+
skipServe: true,
|
|
26
|
+
};
|
|
27
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
|
28
|
+
await addFiles(tree, projectConfig, options);
|
|
29
|
+
if (!options.skipFormat) {
|
|
30
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
31
|
+
}
|
|
32
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
33
33
|
}
|
|
34
34
|
exports.cypressComponentConfiguration = cypressComponentConfiguration;
|
|
35
|
-
function addFiles(tree, projectConfig, opts) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
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. */
|
|
35
|
+
async function addFiles(tree, projectConfig, opts) {
|
|
36
|
+
const { addMountDefinition, addDefaultCTConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/config'));
|
|
37
|
+
const ctFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
|
|
38
|
+
const updatedCommandFile = await addMountDefinition(tree.read(ctFile, 'utf-8'));
|
|
39
|
+
tree.write(ctFile, `import { mount } from 'cypress/react18';\nimport './styles.ct.css';\n${updatedCommandFile}`);
|
|
40
|
+
const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
|
|
41
|
+
const updatedCyConfig = await addDefaultCTConfig(tree.read(cyFile, 'utf-8'));
|
|
42
|
+
tree.write(cyFile, `import { nxComponentTestingPreset } from '@nx/next/plugins/component-testing';\n${updatedCyConfig}`);
|
|
43
|
+
const isUsingTailwind = ['js', 'cjs'].some((ext) => tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, `tailwind.config.${ext}`)));
|
|
44
|
+
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. */
|
|
46
45
|
${isUsingTailwind
|
|
47
|
-
|
|
46
|
+
? `@tailwind base;
|
|
48
47
|
@tailwind components;
|
|
49
48
|
@tailwind utilities;`
|
|
50
|
-
|
|
49
|
+
: ''}
|
|
51
50
|
`);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
if ((0, ct_utils_1.isComponent)(tree, filePath)) {
|
|
63
|
-
filePaths.push(filePath);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
for (const filePath of filePaths) {
|
|
67
|
-
yield (0, react_1.componentTestGenerator)(tree, {
|
|
68
|
-
project: opts.project,
|
|
69
|
-
componentPath: filePath,
|
|
70
|
-
});
|
|
51
|
+
if (opts.generateTests) {
|
|
52
|
+
const filePaths = [];
|
|
53
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot, (filePath) => {
|
|
54
|
+
const fromProjectRootPath = (0, path_1.relative)(projectConfig.root, filePath);
|
|
55
|
+
// we don't generate tests for pages/server-side/appDir components
|
|
56
|
+
if (fromProjectRootPath.includes('pages') ||
|
|
57
|
+
fromProjectRootPath.includes('server') ||
|
|
58
|
+
fromProjectRootPath.includes('app')) {
|
|
59
|
+
return;
|
|
71
60
|
}
|
|
61
|
+
if ((0, ct_utils_1.isComponent)(tree, filePath)) {
|
|
62
|
+
filePaths.push(filePath);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
for (const filePath of filePaths) {
|
|
66
|
+
await (0, react_1.componentTestGenerator)(tree, {
|
|
67
|
+
project: opts.project,
|
|
68
|
+
componentPath: filePath,
|
|
69
|
+
});
|
|
72
70
|
}
|
|
73
|
-
}
|
|
71
|
+
}
|
|
74
72
|
}
|
|
75
73
|
exports.default = cypressComponentConfiguration;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nextInitSchematic = exports.nextInitGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const versions_1 = require("@nx/react/src/utils/versions");
|
|
7
6
|
const init_1 = require("@nx/react/src/generators/init/init");
|
|
@@ -19,39 +18,43 @@ function updateDependencies(host) {
|
|
|
19
18
|
'eslint-config-next': versions_2.eslintConfigNextVersion,
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
|
-
function nextInitGenerator(host, schema) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
(0, add_gitignore_entry_1.addGitIgnoreEntry)(host);
|
|
53
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
21
|
+
async function nextInitGenerator(host, schema) {
|
|
22
|
+
const tasks = [];
|
|
23
|
+
tasks.push(await (0, js_1.initGenerator)(host, {
|
|
24
|
+
...schema,
|
|
25
|
+
skipFormat: true,
|
|
26
|
+
}));
|
|
27
|
+
if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
|
|
28
|
+
const { jestInitGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_2.nxVersion);
|
|
29
|
+
const jestTask = await jestInitGenerator(host, schema);
|
|
30
|
+
tasks.push(jestTask);
|
|
31
|
+
}
|
|
32
|
+
if (schema.e2eTestRunner === 'cypress') {
|
|
33
|
+
const { cypressInitGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_2.nxVersion);
|
|
34
|
+
const cypressTask = await cypressInitGenerator(host, {});
|
|
35
|
+
tasks.push(cypressTask);
|
|
36
|
+
}
|
|
37
|
+
else if (schema.e2eTestRunner === 'playwright') {
|
|
38
|
+
const { initGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_2.nxVersion);
|
|
39
|
+
const playwrightTask = await initGenerator(host, {
|
|
40
|
+
skipFormat: true,
|
|
41
|
+
skipPackageJson: schema.skipPackageJson,
|
|
42
|
+
});
|
|
43
|
+
tasks.push(playwrightTask);
|
|
44
|
+
}
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
// TODO(jack): remove once the React Playwright PR lands first
|
|
47
|
+
const reactTask = await (0, init_1.default)(host, {
|
|
48
|
+
...schema,
|
|
49
|
+
skipFormat: true,
|
|
54
50
|
});
|
|
51
|
+
tasks.push(reactTask);
|
|
52
|
+
if (!schema.skipPackageJson) {
|
|
53
|
+
const installTask = updateDependencies(host);
|
|
54
|
+
tasks.push(installTask);
|
|
55
|
+
}
|
|
56
|
+
(0, add_gitignore_entry_1.addGitIgnoreEntry)(host);
|
|
57
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
55
58
|
}
|
|
56
59
|
exports.nextInitGenerator = nextInitGenerator;
|
|
57
60
|
exports.default = nextInitGenerator;
|