@nx/next 17.3.0-beta.1 → 17.3.0-beta.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "17.3.0-beta.1",
3
+ "version": "17.3.0-beta.3",
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, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "next": ">=13.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@nx/devkit": "17.3.0-beta.1",
37
+ "@nx/devkit": "17.3.0-beta.3",
38
38
  "@babel/plugin-proposal-decorators": "^7.22.7",
39
39
  "@svgr/webpack": "^8.0.1",
40
40
  "chalk": "^4.1.0",
@@ -45,12 +45,12 @@
45
45
  "url-loader": "^4.1.1",
46
46
  "tslib": "^2.3.0",
47
47
  "webpack-merge": "^5.8.0",
48
- "@nx/js": "17.3.0-beta.1",
49
- "@nx/eslint": "17.3.0-beta.1",
50
- "@nx/react": "17.3.0-beta.1",
51
- "@nx/web": "17.3.0-beta.1",
52
- "@nx/workspace": "17.3.0-beta.1",
53
- "@nrwl/next": "17.3.0-beta.1"
48
+ "@nx/js": "17.3.0-beta.3",
49
+ "@nx/eslint": "17.3.0-beta.3",
50
+ "@nx/react": "17.3.0-beta.3",
51
+ "@nx/web": "17.3.0-beta.3",
52
+ "@nx/workspace": "17.3.0-beta.3",
53
+ "@nrwl/next": "17.3.0-beta.3"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -10,7 +10,16 @@ function updatePackageJson(packageJson, context) {
10
10
  }
11
11
  packageJson.dependencies ??= {};
12
12
  // These are always required for a production Next.js app to run.
13
- const requiredPackages = ['react', 'react-dom', 'next', 'typescript'];
13
+ // sharp is for next/image https://nextjs.org/docs/messages/sharp-missing-in-production
14
+ // critters is required for experimental optimizing CSS
15
+ const requiredPackages = [
16
+ 'react',
17
+ 'react-dom',
18
+ 'next',
19
+ 'typescript',
20
+ 'sharp',
21
+ 'critters',
22
+ ];
14
23
  for (const pkg of requiredPackages) {
15
24
  const externalNode = context.projectGraph.externalNodes[`npm:${pkg}`];
16
25
  if (externalNode) {
@@ -294,7 +294,7 @@ function createAppJsx(name) {
294
294
  <path strokeWidth="2" d="M23 6v14.1667C23 21.7307 21.7307 23 20.1667 23H6c0-3.128 2.53867-5.6667 5.6667-5.6667 3.128 0 5.6666-2.5386 5.6666-5.6666C17.3333 8.53867 19.872 6 23 6Z" />
295
295
  </svg>
296
296
  <h2>
297
- NxCloud
297
+ Nx Cloud
298
298
  <span>
299
299
  Enable faster CI & better DX
300
300
  </span>
@@ -5,6 +5,8 @@ const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
5
5
  async function update(tree) {
6
6
  const projects = (0, devkit_1.getProjects)(tree);
7
7
  projects.forEach((project) => {
8
+ if (!(0, eslint_file_1.isEslintConfigSupported)(tree, project.root))
9
+ return;
8
10
  (0, eslint_file_1.updateOverrideInLintConfig)(tree, project.root, (o) => o.rules?.['@next/next/no-html-link-for-pages'] &&
9
11
  o.files?.includes('**/*.*'), (o) => undefined);
10
12
  });
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { CreateDependencies, CreateNodes } from '@nx/devkit';
2
3
  export interface NextPluginOptions {
3
4
  buildTargetName?: string;
@@ -6,3 +7,4 @@ export interface NextPluginOptions {
6
7
  }
7
8
  export declare const createDependencies: CreateDependencies;
8
9
  export declare const createNodes: CreateNodes<NextPluginOptions>;
10
+ export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodes = exports.createDependencies = void 0;
3
+ exports.loadEsmModule = exports.createNodes = exports.createDependencies = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const path_1 = require("path");
6
6
  const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
@@ -23,9 +23,8 @@ const createDependencies = () => {
23
23
  return [];
24
24
  };
25
25
  exports.createDependencies = createDependencies;
26
- // TODO(nicholas): Add support for .mjs files
27
26
  exports.createNodes = [
28
- '**/next.config.{js, cjs}',
27
+ '**/next.config.{js,cjs,mjs}',
29
28
  async (configFilePath, options, context) => {
30
29
  const projectRoot = (0, path_1.dirname)(configFilePath);
31
30
  // Do not create a project if package.json and project.json isn't there.
@@ -52,7 +51,7 @@ exports.createNodes = [
52
51
  },
53
52
  ];
54
53
  async function buildNextTargets(nextConfigPath, projectRoot, options, context) {
55
- const nextConfig = getNextConfig(nextConfigPath, context);
54
+ const nextConfig = await getNextConfig(nextConfigPath, context);
56
55
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
57
56
  const targets = {};
58
57
  targets[options.buildTargetName] = await getBuildTargetConfig(namedInputs, projectRoot, nextConfig);
@@ -107,11 +106,22 @@ async function getOutputs(projectRoot, nextConfig) {
107
106
  // If nextConfig is an object, directly use its 'distDir' property.
108
107
  dir = nextConfig.distDir;
109
108
  }
110
- return `{workspaceRoot}/${projectRoot}/${dir}`;
109
+ if (projectRoot === '.') {
110
+ return `{projectRoot}/${dir}`;
111
+ }
112
+ else {
113
+ return `{workspaceRoot}/${projectRoot}/${dir}`;
114
+ }
111
115
  }
112
- function getNextConfig(configFilePath, context) {
116
+ async function getNextConfig(configFilePath, context) {
113
117
  const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
114
- const module = load(resolvedPath);
118
+ let module;
119
+ if ((0, path_1.extname)(configFilePath) === '.mjs') {
120
+ module = await loadEsmModule(resolvedPath);
121
+ }
122
+ else {
123
+ module = load(resolvedPath);
124
+ }
115
125
  return module.default ?? module;
116
126
  }
117
127
  function normalizeOptions(options) {
@@ -131,16 +141,29 @@ function getInputs(namedInputs) {
131
141
  },
132
142
  ];
133
143
  }
144
+ const packageInstallationDirectories = ['node_modules', '.yarn'];
134
145
  /**
135
146
  * Load the module after ensuring that the require cache is cleared.
136
147
  */
137
148
  function load(path) {
138
149
  // Clear cache if the path is in the cache
139
150
  if (require.cache[path]) {
140
- for (const k of Object.keys(require.cache)) {
141
- delete require.cache[k];
151
+ for (const key of Object.keys(require.cache)) {
152
+ if (!packageInstallationDirectories.some((dir) => key.includes(dir))) {
153
+ delete require.cache[key];
154
+ }
142
155
  }
143
156
  }
144
157
  // Then require
145
158
  return require(path);
146
159
  }
160
+ /**
161
+ * Lazily compiled dynamic import loader function.
162
+ */
163
+ let dynamicLoad;
164
+ function loadEsmModule(modulePath) {
165
+ const modulePathWithCacheBust = `${modulePath}?version=${Date.now()}`;
166
+ dynamicLoad ??= new Function('modulePath', `return import(modulePath);`);
167
+ return dynamicLoad(modulePathWithCacheBust);
168
+ }
169
+ exports.loadEsmModule = loadEsmModule;