@nx/next 20.5.0-beta.4 → 20.5.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 +7 -7
- package/src/generators/application/application.js +3 -2
- package/src/generators/library/library.js +1 -0
- package/src/generators/setup-tailwind/files/postcss.config.js__tmpl__ +15 -0
- package/src/generators/setup-tailwind/files/tailwind.config.js__tmpl__ +23 -0
- package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.d.ts +3 -0
- package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.js +27 -0
- package/src/generators/setup-tailwind/lib/update-project.d.ts +3 -0
- package/src/generators/setup-tailwind/lib/update-project.js +11 -0
- package/src/generators/setup-tailwind/schema.d.ts +6 -0
- package/src/generators/setup-tailwind/schema.js +2 -0
- package/src/generators/setup-tailwind/schema.json +47 -0
- package/src/generators/setup-tailwind/setup-tailwind.d.ts +4 -0
- package/src/generators/setup-tailwind/setup-tailwind.js +34 -0
- package/tailwind.d.ts +6 -2
- package/tailwind.js +30 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "20.5.0-beta.
|
|
3
|
+
"version": "20.5.0-beta.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Next.js plugin for Nx contains executors and generators for managing Next.js applications and libraries within an Nx workspace. It provides:\n\n\n- Scaffolding for creating, building, serving, linting, and testing Next.js applications.\n\n- Integration with building, serving, and exporting a Next.js application.\n\n- Integration with React libraries within the workspace. \n\nWhen using Next.js in Nx, you get the out-of-the-box support for TypeScript, Playwright, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"next": ">=14.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nx/devkit": "20.5.0-beta.
|
|
38
|
+
"@nx/devkit": "20.5.0-beta.5",
|
|
39
39
|
"@babel/plugin-proposal-decorators": "^7.22.7",
|
|
40
40
|
"@svgr/webpack": "^8.1.0",
|
|
41
41
|
"copy-webpack-plugin": "^10.2.4",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"semver": "^7.5.3",
|
|
45
45
|
"tslib": "^2.3.0",
|
|
46
46
|
"webpack-merge": "^5.8.0",
|
|
47
|
-
"@nx/js": "20.5.0-beta.
|
|
48
|
-
"@nx/eslint": "20.5.0-beta.
|
|
49
|
-
"@nx/react": "20.5.0-beta.
|
|
50
|
-
"@nx/web": "20.5.0-beta.
|
|
51
|
-
"@nx/webpack": "20.5.0-beta.
|
|
47
|
+
"@nx/js": "20.5.0-beta.5",
|
|
48
|
+
"@nx/eslint": "20.5.0-beta.5",
|
|
49
|
+
"@nx/react": "20.5.0-beta.5",
|
|
50
|
+
"@nx/web": "20.5.0-beta.5",
|
|
51
|
+
"@nx/webpack": "20.5.0-beta.5",
|
|
52
52
|
"@phenomnomnominal/tsquery": "~5.0.1"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
@@ -4,7 +4,7 @@ exports.applicationGenerator = applicationGenerator;
|
|
|
4
4
|
exports.applicationGeneratorInternal = applicationGeneratorInternal;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
|
-
const
|
|
7
|
+
const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
|
|
8
8
|
const versions_1 = require("@nx/react/src/utils/versions");
|
|
9
9
|
const version_utils_1 = require("@nx/react/src/utils/version-utils");
|
|
10
10
|
const normalize_options_1 = require("./lib/normalize-options");
|
|
@@ -58,7 +58,7 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
58
58
|
const lintTask = await (0, add_linting_1.addLinting)(host, options);
|
|
59
59
|
tasks.push(lintTask);
|
|
60
60
|
if (options.style === 'tailwind') {
|
|
61
|
-
const tailwindTask = await (0,
|
|
61
|
+
const tailwindTask = await (0, setup_tailwind_1.setupTailwindGenerator)(host, {
|
|
62
62
|
project: options.projectName,
|
|
63
63
|
});
|
|
64
64
|
tasks.push(tailwindTask);
|
|
@@ -89,6 +89,7 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
89
89
|
};
|
|
90
90
|
if (options.unitTestRunner && options.unitTestRunner !== 'none') {
|
|
91
91
|
devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
|
|
92
|
+
devDependencies['@testing-library/dom'] = versions_1.testingLibraryDomVersion;
|
|
92
93
|
}
|
|
93
94
|
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { tslib: versions_2.tsLibVersion }, devDependencies));
|
|
94
95
|
}
|
|
@@ -44,6 +44,7 @@ async function libraryGeneratorInternal(host, rawOptions) {
|
|
|
44
44
|
}
|
|
45
45
|
if (options.unitTestRunner && options.unitTestRunner !== 'none') {
|
|
46
46
|
devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
|
|
47
|
+
devDependencies['@testing-library/dom'] = versions_1.testingLibraryDomVersion;
|
|
47
48
|
}
|
|
48
49
|
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { tslib: versions_2.tsLibVersion }, devDependencies));
|
|
49
50
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { join } = require('path');
|
|
2
|
+
|
|
3
|
+
// Note: If you use library-specific PostCSS/Tailwind configuration then you should remove the `postcssConfig` build
|
|
4
|
+
// option from your application's configuration (i.e. project.json).
|
|
5
|
+
//
|
|
6
|
+
// See: https://nx.dev/guides/using-tailwind-css-in-react#step-4:-applying-configuration-to-libraries
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
plugins: {
|
|
10
|
+
tailwindcss: {
|
|
11
|
+
config: join(__dirname, 'tailwind.config.js'),
|
|
12
|
+
},
|
|
13
|
+
autoprefixer: {},
|
|
14
|
+
},
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// const { createGlobPatternsForDependencies } = require('@nx/next/tailwind');
|
|
2
|
+
|
|
3
|
+
// The above utility import will not work if you are using Next.js' --turbo.
|
|
4
|
+
// Instead you will have to manually add the dependent paths to be included.
|
|
5
|
+
// For example
|
|
6
|
+
// ../libs/buttons/**/*.{ts,tsx,js,jsx,html}', <--- Adding a shared lib
|
|
7
|
+
// !../libs/buttons/**/*.{stories,spec}.{ts,tsx,js,jsx,html}', <--- Skip adding spec/stories files from shared lib
|
|
8
|
+
|
|
9
|
+
// If you are **not** using `--turbo` you can uncomment both lines 1 & 19.
|
|
10
|
+
// A discussion of the issue can be found: https://github.com/nrwl/nx/issues/26510
|
|
11
|
+
|
|
12
|
+
/** @type {import('tailwindcss').Config} */
|
|
13
|
+
module.exports = {
|
|
14
|
+
content: [
|
|
15
|
+
'./{src,pages,components,app}/**/*.{ts,tsx,js,jsx,html}',
|
|
16
|
+
'!./{src,pages,components,app}/**/*.{stories,spec}.{ts,tsx,js,jsx,html}',
|
|
17
|
+
// ...createGlobPatternsForDependencies(__dirname)
|
|
18
|
+
],
|
|
19
|
+
theme: {
|
|
20
|
+
extend: {},
|
|
21
|
+
},
|
|
22
|
+
plugins: [],
|
|
23
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addTailwindStyleImports = addTailwindStyleImports;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
// base directories and file types to simplify locating the stylesheet
|
|
6
|
+
const baseDirs = ['src', 'pages', 'src/pages', 'src/app', 'app'];
|
|
7
|
+
const fileNames = ['styles', 'global'];
|
|
8
|
+
const extensions = ['.css', '.scss', '.less'];
|
|
9
|
+
const knownLocations = baseDirs.flatMap((dir) => fileNames.flatMap((name) => extensions.map((ext) => `${dir}/${name}${ext}`)));
|
|
10
|
+
function addTailwindStyleImports(tree, project, _options) {
|
|
11
|
+
const candidates = knownLocations.map((currentPath) => (0, devkit_1.joinPathFragments)(project.root, currentPath));
|
|
12
|
+
const stylesPath = candidates.find((currentStylePath) => tree.exists(currentStylePath));
|
|
13
|
+
if (stylesPath) {
|
|
14
|
+
const content = tree.read(stylesPath).toString();
|
|
15
|
+
tree.write(stylesPath, `@tailwind base;\n@tailwind components;\n@tailwind utilities;\n${content}`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
devkit_1.logger.warn((0, devkit_1.stripIndents) `
|
|
19
|
+
Could not find stylesheet to update. Add the following imports to your stylesheet (e.g. styles.css):
|
|
20
|
+
|
|
21
|
+
@tailwind base;
|
|
22
|
+
@tailwind components;
|
|
23
|
+
@tailwind utilities;
|
|
24
|
+
|
|
25
|
+
See our guide for more details: https://nx.dev/guides/using-tailwind-css-in-react`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateProject = updateProject;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function updateProject(tree, config, options) {
|
|
6
|
+
if (config?.targets?.build?.executor === '@nx/webpack:webpack') {
|
|
7
|
+
config.targets.build.options ??= {};
|
|
8
|
+
config.targets.build.options.postcssConfig = (0, devkit_1.joinPathFragments)(config.root, 'postcss.config.js');
|
|
9
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, config);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxNextTailwindSetupGenerator",
|
|
5
|
+
"title": "Configures Tailwind CSS for an application or a buildable/publishable library.",
|
|
6
|
+
"description": "Adds the Tailwind CSS configuration files for a Next.js project and installs, if needed, the packages required for Tailwind CSS to work.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g setup-tailwind --project=my-app",
|
|
11
|
+
"description": "Initialize Tailwind configuration for the `my-app` project."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {
|
|
15
|
+
"project": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "The name of the project to add the Tailwind CSS setup for.",
|
|
18
|
+
"alias": "p",
|
|
19
|
+
"$default": {
|
|
20
|
+
"$source": "argv",
|
|
21
|
+
"index": 0
|
|
22
|
+
},
|
|
23
|
+
"x-dropdown": "projects",
|
|
24
|
+
"x-prompt": "What project would you like to add the Tailwind CSS setup?",
|
|
25
|
+
"x-priority": "important"
|
|
26
|
+
},
|
|
27
|
+
"buildTarget": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "The name of the target used to build the project. This option is not needed in most cases.",
|
|
30
|
+
"default": "build",
|
|
31
|
+
"x-priority": "important"
|
|
32
|
+
},
|
|
33
|
+
"skipFormat": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"description": "Skips formatting the workspace after the generator completes.",
|
|
36
|
+
"x-priority": "internal"
|
|
37
|
+
},
|
|
38
|
+
"skipPackageJson": {
|
|
39
|
+
"type": "boolean",
|
|
40
|
+
"default": false,
|
|
41
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
42
|
+
"x-priority": "internal"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"required": ["project"]
|
|
47
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import type { SetupTailwindOptions } from './schema';
|
|
3
|
+
export declare function setupTailwindGenerator(tree: Tree, options: SetupTailwindOptions): Promise<GeneratorCallback>;
|
|
4
|
+
export default setupTailwindGenerator;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupTailwindGenerator = setupTailwindGenerator;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("@nx/react/src/utils/versions");
|
|
6
|
+
const add_tailwind_style_imports_1 = require("./lib/add-tailwind-style-imports");
|
|
7
|
+
const update_project_1 = require("./lib/update-project");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
async function setupTailwindGenerator(tree, options) {
|
|
10
|
+
const tasks = [];
|
|
11
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
12
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'postcss.config.js')) ||
|
|
13
|
+
tree.exists((0, devkit_1.joinPathFragments)(project.root, 'tailwind.config.js'))) {
|
|
14
|
+
devkit_1.logger.info(`Skipping setup since there are existing PostCSS or Tailwind configuration files. For manual setup instructions, see https://nx.dev/guides/using-tailwind-css-in-react.`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), project.root, {
|
|
18
|
+
tmpl: '',
|
|
19
|
+
});
|
|
20
|
+
(0, add_tailwind_style_imports_1.addTailwindStyleImports)(tree, project, options);
|
|
21
|
+
(0, update_project_1.updateProject)(tree, project, options);
|
|
22
|
+
if (!options.skipPackageJson) {
|
|
23
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
24
|
+
autoprefixer: versions_1.autoprefixerVersion,
|
|
25
|
+
postcss: versions_1.postcssVersion,
|
|
26
|
+
tailwindcss: versions_1.tailwindcssVersion,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
if (!options.skipFormat) {
|
|
30
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
31
|
+
}
|
|
32
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
33
|
+
}
|
|
34
|
+
exports.default = setupTailwindGenerator;
|
package/tailwind.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates a set of glob patterns based off the source root of the app and its dependencies
|
|
3
|
+
* @param dirPath workspace relative directory path that will be used to infer the parent project and dependencies
|
|
4
|
+
* @param fileGlobPattern pass a custom glob pattern to be used
|
|
5
|
+
*/
|
|
6
|
+
export declare function createGlobPatternsForDependencies(dirPath: string, fileGlobPatternToInclude?: string, fileGlobPatternToExclude?: string): string[];
|
package/tailwind.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGlobPatternsForDependencies =
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
3
|
+
exports.createGlobPatternsForDependencies = createGlobPatternsForDependencies;
|
|
4
|
+
const generate_globs_1 = require("@nx/js/src/utils/generate-globs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
/**
|
|
7
|
+
* Generates a set of glob patterns based off the source root of the app and its dependencies
|
|
8
|
+
* @param dirPath workspace relative directory path that will be used to infer the parent project and dependencies
|
|
9
|
+
* @param fileGlobPattern pass a custom glob pattern to be used
|
|
10
|
+
*/
|
|
11
|
+
function createGlobPatternsForDependencies(dirPath, fileGlobPatternToInclude = '/**/*.{tsx,ts,jsx,js,html}', fileGlobPatternToExclude = '/**/*.{stories,spec}.{tsx,ts,jsx,js,html}') {
|
|
12
|
+
try {
|
|
13
|
+
return [
|
|
14
|
+
...(0, generate_globs_1.createGlobPatternsForDependencies)(dirPath, fileGlobPatternToInclude).map((glob) => (0, path_1.relative)(dirPath, glob)),
|
|
15
|
+
...(0, generate_globs_1.createGlobPatternsForDependencies)(dirPath, fileGlobPatternToExclude).map((glob) => `!${(0, path_1.relative)(dirPath, glob)}`),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
/**
|
|
20
|
+
* It should not be possible to reach this point when the utility is invoked as part of the normal
|
|
21
|
+
* lifecycle of Nx executors. However, other tooling, such as the VSCode Tailwind IntelliSense plugin
|
|
22
|
+
* or JetBrains editors such as WebStorm, may execute the tailwind.config.js file in order to provide
|
|
23
|
+
* autocomplete features, for example.
|
|
24
|
+
*
|
|
25
|
+
* In order to best support that use-case, we therefore do not hard error when the ProjectGraph is
|
|
26
|
+
* fundamently unavailable in this tailwind-specific context.
|
|
27
|
+
*/
|
|
28
|
+
console.warn('\nWARNING: There was an error creating glob patterns, returning an empty array\n' +
|
|
29
|
+
`${e.message}\n`);
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
}
|