chore(repo): update nx to 23.0.0-beta.7#35565
Conversation
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 8cfd0de
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:
We fixed three test failures caused by the update-devkit-deep-imports migration changes. The devkit implementation was extended to also process @nx/devkit/internal imports (not just @nx/devkit/src/…), the nuxt test mock was updated to spread jest.requireActual so only loadConfigFile is overridden, and the workspace-plugin snapshot was updated to reflect the new multi-line import structure produced by the updated template.
Note
⏳ We are verifying this fix by re-running a subset of the 3 failed tasks that were analyzed.
Suggested Fix changes
diff --git a/packages/devkit/src/migrations/update-23-0-0/update-deep-imports.ts b/packages/devkit/src/migrations/update-23-0-0/update-deep-imports.ts
index e0381173..b22f6589 100644
--- a/packages/devkit/src/migrations/update-23-0-0/update-deep-imports.ts
+++ b/packages/devkit/src/migrations/update-23-0-0/update-deep-imports.ts
@@ -83,7 +83,11 @@ export default async function updateDevkitDeepImports(
return;
}
const original = tree.read(filePath, 'utf-8');
- if (!original || !original.includes(DEEP_IMPORT_PREFIX)) {
+ if (
+ !original ||
+ (!original.includes(DEEP_IMPORT_PREFIX) &&
+ !original.includes(INTERNAL_SPECIFIER))
+ ) {
return;
}
const updated = rewriteDevkitDeepImports(original);
@@ -117,7 +121,11 @@ export function rewriteDevkitDeepImports(source: string): string {
for (const stmt of sourceFile.statements) {
if (!ts.isImportDeclaration(stmt)) continue;
if (!ts.isStringLiteral(stmt.moduleSpecifier)) continue;
- if (!stmt.moduleSpecifier.text.startsWith(DEEP_IMPORT_PREFIX)) continue;
+ if (
+ !stmt.moduleSpecifier.text.startsWith(DEEP_IMPORT_PREFIX) &&
+ stmt.moduleSpecifier.text !== INTERNAL_SPECIFIER
+ )
+ continue;
const replacement = buildReplacement(stmt, sourceFile);
changes.push(
diff --git a/packages/nuxt/src/plugins/plugin.spec.ts b/packages/nuxt/src/plugins/plugin.spec.ts
index 11eb31eb..e1a0f6c7 100644
--- a/packages/nuxt/src/plugins/plugin.spec.ts
+++ b/packages/nuxt/src/plugins/plugin.spec.ts
@@ -3,6 +3,7 @@ import { createNodes } from './plugin';
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
jest.mock('@nx/devkit/internal', () => ({
+ ...jest.requireActual('@nx/devkit/internal'),
loadConfigFile: jest.fn().mockImplementation(() => {
return Promise.resolve({
buildDir: '../dist/my-app/.nuxt',
diff --git a/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap b/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap
index e31ebbd6..4a789e2c 100644
--- a/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap
+++ b/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap
@@ -250,11 +250,15 @@ function mockEslintConfig(config: any) {
`;
exports[`create-nodes-plugin/generator generator should run successfully 3`] = `
-"import { formatFiles, getProjects, Tree } from '@nx/devkit';
+"import {
+ formatFiles,
+ getProjects,
+ Tree,
+ replaceProjectConfigurationsWithPlugin,
+} from '@nx/devkit';
import { createNodes } from '../../plugins/plugin';
import { createProjectRootMappingsFromProjectConfigurations } from 'nx/src/project-graph/utils/find-project-for-path';
-import { replaceProjectConfigurationsWithPlugin } from '@nx/devkit/src/utils/replace-project-configuration-with-plugin';
export default async function update(tree: Tree) {
const proj = Object.fromEntries(getProjects(tree).entries());
Or Apply changes locally with:
npx nx-cloud apply-locally tcjz-7eua
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
) ## Current Behavior The 23.0.0-beta.6 `@nx/devkit` deep-import migration (#35541) catches non-named-import shapes (default / namespace / side-effect / `require()` / dynamic `import()` / `jest.mock`-style calls) by running a regex sweep over the file: ```ts const FALLBACK_RE = /(['"])@nx\/devkit\/src\/[^'"\n]+?\1/g; updated = updated.replace( FALLBACK_RE, (_match, quote: string) => `${quote}${INTERNAL_SPECIFIER}${quote}` ); ``` That sweep matches **any** `'@nx/devkit/src/...'` literal anywhere in the file, regardless of context. As a result the migration mangled: - **Test fixtures inside template literals** — including the migration's own `update-deep-imports.spec.ts`. Examples observed in the wild: `packages/devkit/src/migrations/update-23-0-0/update-deep-imports.spec.ts`, `packages/expo/src/utils/expo-project-detection.spec.ts`, `packages/nuxt/src/plugins/plugin.spec.ts`, `packages/react-native/src/utils/react-native-project-detection.spec.ts`, etc. ([#35565](#35565)) - **`typeof import('@nx/devkit/src/...')` type queries** — e.g. `libs/shared/npm/src/lib/local-nx-utils/parse-target-string.ts` in nrwl/nx-console, where the type now claims `@nx/devkit/internal` while the runtime `importPath` next to it is built dynamically and still points at `src/...`. ([nrwl/nx-console#3131](nrwl/nx-console#3131)) - **Deep-import paths in comments**, doc strings, and arbitrary string-literal arguments to unrelated functions. ## Expected Behavior The migration only rewrites deep-import paths that are *actually* import sites. Everything else (template strings, type queries, comments, unrelated calls) is left alone. This is implemented by replacing the regex sweep with a TypeScript-AST visitor that only rewrites the string-literal argument of `CallExpression` nodes whose callee is one of: - `require` (identifier) - the dynamic-`import` keyword - `jest.mock` / `jest.unmock` / `jest.doMock` / `jest.dontMock` / `jest.requireActual` / `jest.requireMock` - `vi.mock` / `vi.unmock` / `vi.doMock` / `vi.dontMock` / `vi.requireActual` / `vi.requireMock` / `vi.importActual` / `vi.importMock` Type queries (`ImportTypeNode`), template literals, and comments are all naturally untouched because they are not `CallExpression` nodes — no allowlist needed. Quote style is preserved per literal. The named-import bucketing pass and the duplicate-collapse pass are unchanged. ### Tests 10 new unit tests: - 5 in a new `non-runtime string literals` block guarding template literals, `typeof import(...)` type queries, block comments, line comments, and unrelated call expressions. - 5 in a new `mock helper calls` block covering `jest.mock`, `jest.requireActual`, `vi.mock`, `vi.importActual`, and a paired `import` + `jest.mock` + `jest.requireActual` combination. All 39 unit tests pass; `nx build devkit` is clean. ## Related Issue(s) Follow-up to #35541. Workspaces that have already merged the bad rewrites need to revert those files by hand — there's no general way to undo the over-rewrites without losing the legitimate ones. --------- Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com> Co-authored-by: FrozenPandaz <FrozenPandaz@users.noreply.github.com>
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Updating Nx from 23.0.0-beta.4 to 23.0.0-beta.7