Skip to content

Commit

Permalink
Merge branch 'master' into bump-pnpm-to-9
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed May 17, 2024
2 parents 275dc45 + 248949f commit ae7c330
Show file tree
Hide file tree
Showing 54 changed files with 293 additions and 121 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/web/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
"default": false
},
"strict": {
"type": "boolean",
"description": "Creates an application with strict mode and strict type checking.",
"default": true
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside workspace.json",
"type": "boolean",
Expand Down
5 changes: 5 additions & 0 deletions docs/shared/features/automate-updating-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ This fetches the specified version of the `nx` package, analyzes the dependencie
- The `package.json` being updated
- A `migrations.json` being generated if there are pending migrations.

{% callout type="note" title="Dependency Updates" %}
The migrations will update the `@nx/*` packages to the desired version. Subsequently, these packages _may_ also update other dependencies in your `package.json` to new versions if support has been added for them.
For example, migrating `@nx/react` to the latest version may also update the `react` version if support has been added for the latest version.
{% /callout %}

At this point, no packages have been installed, and no other files have been touched.

Now, you can inspect `package.json` to see if the changes make sense. Sometimes the migration can update a package to a version that is either not allowed or conflicts with another package. Feel free to manually apply the desired adjustments.
Expand Down
2 changes: 1 addition & 1 deletion e2e/node/src/node-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@nx/e2e/utils';
import { join } from 'path';

describe('Node Applications + webpack', () => {
xdescribe('Node Applications + webpack', () => {
let proj: string;
beforeAll(() => {
proj = newProject({
Expand Down
4 changes: 2 additions & 2 deletions graph/ui-icons/src/lib/technologies/gradle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { FC, SVGProps } from 'react';
export const GradleIcon: FC<SVGProps<SVGSVGElement>> = (props) => (
<svg
role="img"
viewBox="0 0 512 512"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
{...props}
>
<title>Gradle</title>
<path d="M427 132.7a61 61 0 00-85-1a6 6 0 000 9l7 8a6 6 0 008 1a35 35 0 0146 53c-48 48-113 -87 -259 -17a20 20 0 00-9 28l25 43a20 20 0 0027 7l1 0l0 0l11-6a257 257 0 0035-26a6 6 0 018 0v0a6 6 0 010 9a263 263 0 01-37 28h0l-11 6a31 31 0 01-15 4a32 32 0 01-28-16L126 219C81 259 53 314 68.13 392.26a6 6 0 006 4.74H100.6a6 6 0 005.93-5.3a40 40 0 0178.62 0a6 6 0 005.72 5.08h26.2a6 6 0 005.7-5.1a40 40 0 0178.6 0a6 6 0 005.7 5h26a6 6 0 005.8-5.72c1-37 10 -79 38.7 -100c98-73 72 -136 49.4 -158.3zm-100 110l-19-9v0a12 12 0 1119 9z" />
<path d="M22.695 4.297a3.807 3.807 0 0 0-5.29-.09.368.368 0 0 0 0 .533l.46.47a.363.363 0 0 0 .474.032 2.182 2.182 0 0 1 2.86 3.291c-3.023 3.02-7.056-5.447-16.211-1.083a1.24 1.24 0 0 0-.534 1.745l1.571 2.713a1.238 1.238 0 0 0 1.681.461l.037-.02-.029.02.688-.384a16.083 16.083 0 0 0 2.193-1.635.384.384 0 0 1 .499-.016.357.357 0 0 1 .016.534 16.435 16.435 0 0 1-2.316 1.741H8.77l-.696.39a1.958 1.958 0 0 1-.963.25 1.987 1.987 0 0 1-1.726-.989L3.9 9.696C1.06 11.72-.686 15.603.26 20.522a.363.363 0 0 0 .354.296h1.675a.363.363 0 0 0 .37-.331 2.478 2.478 0 0 1 4.915 0 .36.36 0 0 0 .357.317h1.638a.363.363 0 0 0 .357-.317 2.478 2.478 0 0 1 4.914 0 .363.363 0 0 0 .358.317h1.627a.363.363 0 0 0 .363-.357c.037-2.294.656-4.93 2.42-6.25 6.108-4.57 4.502-8.486 3.088-9.9zm-6.229 6.901l-1.165-.584a.73.73 0 1 1 1.165.587z" />
</svg>
);
2 changes: 1 addition & 1 deletion graph/ui-icons/src/lib/technologies/nextjs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const NextJSIcon: FC<SVGProps<SVGSVGElement>> = (props) => (
{...props}
>
<title>Next.js</title>
<path d="M11.5725 0c-.1763 0-.3098.0013-.3584.0067-.0516.0053-.2159.021-.3636.0328-3.4088.3073-6.6017 2.1463-8.624 4.9728C1.1004 6.584.3802 8.3666.1082 10.255c-.0962.659-.108.8537-.108 1.7474s.012 1.0884.108 1.7476c.652 4.506 3.8591 8.2919 8.2087 9.6945.7789.2511 1.6.4223 2.5337.5255.3636.04 1.9354.04 2.299 0 1.6117-.1783 2.9772-.577 4.3237-1.2643.2065-.1056.2464-.1337.2183-.1573-.0188-.0139-.8987-1.1938-1.9543-2.62l-1.919-2.592-2.4047-3.5583c-1.3231-1.9564-2.4117-3.556-2.4211-3.556-.0094-.0026-.0187 1.5787-.0235 3.509-.0067 3.3802-.0093 3.5162-.0516 3.596-.061.115-.108.1618-.2064.2134-.075.0374-.1408.0445-.495.0445h-.406l-.1078-.068a.4383.4383 0 01-.1572-.1712l-.0493-.1056.0053-4.703.0067-4.7054.0726-.0915c.0376-.0493.1174-.1125.1736-.143.0962-.047.1338-.0517.5396-.0517.4787 0 .5584.0187.6827.1547.0353.0377 1.3373 1.9987 2.895 4.3608a10760.433 10760.433 0 004.7344 7.1706l1.9002 2.8782.096-.0633c.8518-.5536 1.7525-1.3418 2.4657-2.1627 1.5179-1.7429 2.4963-3.868 2.8247-6.134.0961-.6591.1078-.854.1078-1.7475 0-.8937-.012-1.0884-.1078-1.7476-.6522-4.506-3.8592-8.2919-8.2087-9.6945-.7672-.2487-1.5836-.42-2.4985-.5232-.169-.0176-1.0835-.0366-1.6123-.037zm4.0685 7.217c.3473 0 .4082.0053.4857.047.1127.0562.204.1642.237.2767.0186.061.0234 1.3653.0186 4.3044l-.0067 4.2175-.7436-1.14-.7461-1.14v-3.066c0-1.982.0093-3.0963.0234-3.1502.0375-.1313.1196-.2346.2323-.2955.0961-.0494.1313-.054.4997-.054z" />
<path d="M18.665 21.978C16.758 23.255 14.465 24 12 24 5.377 24 0 18.623 0 12S5.377 0 12 0s12 5.377 12 12c0 3.583-1.574 6.801-4.067 9.001L9.219 7.2H7.2v9.596h1.615V9.251l9.85 12.727Zm-3.332-8.533 1.6 2.061V7.2h-1.6v6.245Z" />
</svg>
);
9 changes: 8 additions & 1 deletion nx-dev/nx-dev/public/images/icons/gradle.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion nx-dev/nx-dev/public/images/icons/nextdotjs.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"types": ["node"]
},
"files": ["<%= offsetFromRoot %>node_modules/@nx/expo/typings/svg.d.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.spec.tsx", "test-setup.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.spec.tsx", "src/test-setup.ts"],
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"]
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": ["node"]
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "test-setup.ts"],
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "src/test-setup.ts"],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
}
60 changes: 59 additions & 1 deletion packages/expo/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('lib', () => {
});
});

describe('--unit-test-runner none', () => {
describe('--unit-test-runner', () => {
it('should not generate test configuration', async () => {
await expoLibraryGenerator(appTree, {
...defaultSchema,
Expand All @@ -220,6 +220,64 @@ describe('lib', () => {
}
`);
});

it('should generate test configuration', async () => {
await expoLibraryGenerator(appTree, {
...defaultSchema,
unitTestRunner: 'jest',
});

expect(appTree.read('my-lib/tsconfig.spec.json', 'utf-8'))
.toMatchInlineSnapshot(`
"{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
"
`);
expect(appTree.read('my-lib/jest.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
displayName: 'my-lib',
resolver: '@nx/jest/plugins/resolver',
preset: 'jest-expo',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
moduleNameMapper: {
'\\\\.svg$': '@nx/expo/plugins/jest/svg-mock',
},
transform: {
'.[jt]sx?$': [
'babel-jest',
{
configFile: __dirname + '/.babelrc.js',
},
],
'^.+.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp|ttf|otf|m4v|mov|mp4|mpeg|mpg|webm|aac|aiff|caf|m4a|mp3|wav|html|pdf|obj)$':
require.resolve('jest-expo/src/preset/assetFileTransformer.js'),
},
coverageDirectory: '../coverage/my-lib',
};
"
`);
});
});

describe('--buildable', () => {
Expand Down
9 changes: 6 additions & 3 deletions packages/expo/src/utils/add-jest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree } from '@nx/devkit';
import { Tree, offsetFromRoot } from '@nx/devkit';
import { configurationGenerator } from '@nx/jest';

export async function addJest(
Expand All @@ -19,7 +19,7 @@ export async function addJest(
project: projectName,
supportTsx: true,
skipSerializers: true,
setupFile: 'none',
setupFile: 'react-native',
compiler: 'babel',
skipPackageJson,
skipFormat: true,
Expand All @@ -34,7 +34,7 @@ export async function addJest(
resolver: '@nx/jest/plugins/resolver',
preset: 'jest-expo',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/test-setup.${js ? 'js' : 'ts'}'],
setupFilesAfterEnv: ['<rootDir>/src/test-setup.${js ? 'js' : 'ts'}'],
moduleNameMapper: {
'\\\\.svg$': '@nx/expo/plugins/jest/svg-mock'
},
Expand All @@ -49,6 +49,9 @@ export async function addJest(
'jest-expo/src/preset/assetFileTransformer.js'
),
},
coverageDirectory: '${offsetFromRoot(
appProjectRoot
)}coverage/${appProjectRoot}'
};`;
host.write(configPath, content);

Expand Down
5 changes: 5 additions & 0 deletions packages/jest/preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { nxPreset } from './preset/jest-preset';

export { nxPreset };

export default nxPreset;
18 changes: 16 additions & 2 deletions packages/jest/src/generators/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,33 @@ describe('jestProject', () => {
expect(tree.exists('libs/lib1/jest.config.js')).toBeTruthy();
});

it('should always use jest.preset.js with --js', async () => {
tree.write('jest.preset.ts', '');
it('should generate a jest.preset.js when it does not exist', async () => {
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
js: true,
} as JestProjectSchema);
expect(tree.exists('libs/lib1/jest.config.js')).toBeTruthy();
expect(tree.exists('jest.preset.js')).toBeTruthy();
expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).toContain(
"preset: '../../jest.preset.js',"
);
});

it('should not override existing jest preset file and should point to it in jest.config files', async () => {
tree.write('jest.preset.mjs', 'export default {}');
await configurationGenerator(tree, {
...defaultOptions,
project: 'lib1',
js: true,
} as JestProjectSchema);
expect(tree.exists('libs/lib1/jest.config.js')).toBeTruthy();
expect(tree.exists('jest.preset.mjs')).toBeTruthy();
expect(tree.read('libs/lib1/jest.config.js', 'utf-8')).toContain(
"preset: '../../jest.preset.mjs',"
);
});

it('should use module.exports with --js flag', async () => {
await configurationGenerator(tree, {
...defaultOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest/src/generators/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@nx/devkit';
import { initGenerator as jsInitGenerator } from '@nx/js';
import { JestPluginOptions } from '../../plugins/plugin';
import { isPresetCjs } from '../../utils/config/is-preset-cjs';
import { getPresetExt } from '../../utils/config/config-file';

const schemaDefaults = {
setupFile: 'none',
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function configurationGeneratorInternal(
tasks.push(ensureDependencies(tree, options));
}

const presetExt = isPresetCjs(tree) ? 'cjs' : 'js';
const presetExt = getPresetExt(tree);

await createJestConfig(tree, options, presetExt);
checkForTestTarget(tree, options);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% if(setupFile === 'react-native') { %>import '@testing-library/jest-native/extend-expect';<% } %>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ projects: await getJestProjectsAsync()
exports[`createJestConfig should generate files 2`] = `
"const nxPreset = require('@nx/jest/preset').default;
module.exports = { ...nxPreset }"
module.exports = { ...nxPreset };"
`;

exports[`createJestConfig should generate files with --js flag 1`] = `
Expand All @@ -25,5 +25,5 @@ projects: await getJestProjectsAsync()
exports[`createJestConfig should generate files with --js flag 2`] = `
"const nxPreset = require('@nx/jest/preset').default;
module.exports = { ...nxPreset }"
module.exports = { ...nxPreset };"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
Tree,
} from '@nx/devkit';
import { join } from 'path';
import type { JestPresetExtension } from '../../../utils/config/config-file';
import { NormalizedJestProjectSchema } from '../schema';

export function createFiles(
tree: Tree,
options: NormalizedJestProjectSchema,
presetExt: 'cjs' | 'js'
presetExt: JestPresetExtension
) {
const projectConfig = readProjectConfiguration(tree, options.project);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,34 @@ import {
type Tree,
} from '@nx/devkit';
import { readTargetDefaultsForTarget } from 'nx/src/project-graph/utils/project-configuration-utils';
import { findRootJestConfig } from '../../../utils/config/find-root-jest-files';
import {
findRootJestConfig,
type JestPresetExtension,
} from '../../../utils/config/config-file';
import type { NormalizedJestProjectSchema } from '../schema';

export async function createJestConfig(
tree: Tree,
options: Partial<NormalizedJestProjectSchema>,
presetExt: 'cjs' | 'js'
presetExt: JestPresetExtension
) {
if (!tree.exists(`jest.preset.${presetExt}`)) {
// preset is always js file.
tree.write(
`jest.preset.${presetExt}`,
`
const nxPreset = require('@nx/jest/preset').default;
if (presetExt === 'mjs') {
tree.write(
`jest.preset.${presetExt}`,
`import { nxPreset } from '@nx/jest/preset.js';
module.exports = { ...nxPreset }`
);
export default { ...nxPreset };`
);
} else {
// js or cjs
tree.write(
`jest.preset.${presetExt}`,
`const nxPreset = require('@nx/jest/preset').default;
module.exports = { ...nxPreset };`
);
}
}
if (options.rootProject) {
// we don't want any config to be made because the `configurationGenerator` will do it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { findRootJestConfig } from '../../../utils/config/find-root-jest-files';
import { NormalizedJestProjectSchema } from '../schema';
import { readProjectConfiguration, type Tree } from '@nx/devkit';
import { findRootJestConfig } from '../../../utils/config/config-file';
import { addPropertyToJestConfig } from '../../../utils/config/update-config';
import { readProjectConfiguration, Tree } from '@nx/devkit';
import type { NormalizedJestProjectSchema } from '../schema';

function isUsingUtilityFunction(host: Tree) {
const rootConfig = findRootJestConfig(host);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest/src/generators/configuration/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface JestProjectSchema {
* @deprecated use setupFile instead
*/
skipSetupFile?: boolean;
setupFile?: 'angular' | 'web-components' | 'none';
setupFile?: 'angular' | 'web-components' | 'react-native' | 'none';
skipSerializers?: boolean;
testEnvironment?: 'node' | 'jsdom' | 'none';
/**
Expand Down

0 comments on commit ae7c330

Please sign in to comment.