@nx/detox 17.0.3 → 17.0.4

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2023 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2024 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -1,4 +1,9 @@
1
- <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
1
+ <p style="text-align: center;">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
+ <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
+ </picture>
6
+ </p>
2
7
 
3
8
  <div style="text-align: center;">
4
9
 
@@ -15,9 +20,9 @@
15
20
 
16
21
  <hr>
17
22
 
18
- # Nx: Smart, Fast and Extensible Build System
23
+ # Nx: Smart Monorepos · Fast CI
19
24
 
20
- Nx is a next generation build system with first class monorepo support and powerful integrations.
25
+ Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
21
26
 
22
27
  This package is a [Detox plugin for Nx](https://nx.dev/detox/overview).
23
28
 
@@ -59,5 +64,5 @@ npx nx@latest init
59
64
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
60
65
 
61
66
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
62
- width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
67
+ width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
63
68
 
package/generators.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "extends": ["@nx/workspace"],
5
5
  "generators": {
6
6
  "init": {
7
- "factory": "./src/generators/init/init#detoxInitGenerator",
7
+ "factory": "./src/generators/init/init#detoxInitGeneratorInternal",
8
8
  "schema": "./src/generators/init/schema.json",
9
9
  "description": "Initialize the `@nrwl/detox` plugin.",
10
10
  "hidden": true
package/migrations.json CHANGED
@@ -99,6 +99,32 @@
99
99
  "alwaysAddToPackageJson": false
100
100
  }
101
101
  }
102
+ },
103
+ "18.0.0": {
104
+ "version": "18.0.0-beta.0",
105
+ "packages": {
106
+ "detox": {
107
+ "version": "^20.16.0",
108
+ "alwaysAddToPackageJson": false
109
+ }
110
+ }
111
+ },
112
+ "18.1.0": {
113
+ "version": "18.1.0-beta.0",
114
+ "packages": {
115
+ "detox": {
116
+ "version": "~20.18.1",
117
+ "alwaysAddToPackageJson": false
118
+ },
119
+ "@config-plugins/detox": {
120
+ "version": "~7.0.0",
121
+ "alwaysAddToPackageJson": false
122
+ },
123
+ "@testing-library/jest-dom": {
124
+ "version": "~6.4.2",
125
+ "alwaysAddToPackageJson": false
126
+ }
127
+ }
102
128
  }
103
129
  }
104
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/detox",
3
- "version": "17.0.3",
3
+ "version": "17.0.4",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Detox contains executors and generators for allowing your workspace to use the powerful Detox integration testing capabilities.",
6
6
  "keywords": [
@@ -25,13 +25,13 @@
25
25
  "main": "./index.js",
26
26
  "types": "index.d.ts",
27
27
  "dependencies": {
28
- "@nx/devkit": "17.0.3",
29
- "@nx/jest": "17.0.3",
30
- "@nx/js": "17.0.3",
31
- "@nx/eslint": "17.0.3",
32
- "@nx/react": "17.0.3",
28
+ "@nx/devkit": "17.0.4",
29
+ "@nx/jest": "17.0.4",
30
+ "@nx/js": "17.0.4",
31
+ "@nx/eslint": "17.0.4",
32
+ "@nx/react": "17.0.4",
33
33
  "tslib": "^2.3.0",
34
- "@nrwl/detox": "17.0.3"
34
+ "@nrwl/detox": "17.0.4"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "detox": "^20.9.0"
package/plugin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createNodes, createDependencies, DetoxPluginOptions, } from './src/plugins/plugin';
package/plugin.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDependencies = exports.createNodes = void 0;
4
+ var plugin_1 = require("./src/plugins/plugin");
5
+ Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
6
+ Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
@@ -8,8 +8,10 @@ const add_linting_1 = require("./lib/add-linting");
8
8
  const add_project_1 = require("./lib/add-project");
9
9
  const create_files_1 = require("./lib/create-files");
10
10
  const normalize_options_1 = require("./lib/normalize-options");
11
+ const ensure_dependencies_1 = require("./lib/ensure-dependencies");
11
12
  async function detoxApplicationGenerator(host, schema) {
12
13
  return await detoxApplicationGeneratorInternal(host, {
14
+ addPlugin: false,
13
15
  projectNameAndRootFormat: 'derived',
14
16
  ...schema,
15
17
  });
@@ -25,10 +27,11 @@ async function detoxApplicationGeneratorInternal(host, schema) {
25
27
  (0, add_project_1.addProject)(host, options);
26
28
  (0, add_git_ignore_entry_1.addGitIgnoreEntry)(host, options);
27
29
  const lintingTask = await (0, add_linting_1.addLinting)(host, options);
30
+ const depsTask = (0, ensure_dependencies_1.ensureDependencies)(host, options);
28
31
  if (!options.skipFormat) {
29
32
  await (0, devkit_1.formatFiles)(host);
30
33
  }
31
- return (0, devkit_1.runTasksInSerial)(initTask, lintingTask);
34
+ return (0, devkit_1.runTasksInSerial)(initTask, lintingTask, depsTask);
32
35
  }
33
36
  exports.detoxApplicationGeneratorInternal = detoxApplicationGeneratorInternal;
34
37
  exports.default = detoxApplicationGenerator;
@@ -15,8 +15,8 @@ async function addLinting(host, options) {
15
15
  tsConfigPaths: [
16
16
  (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'tsconfig.app.json'),
17
17
  ],
18
- eslintFilePatterns: [`${options.e2eProjectRoot}/**/*.{ts,tsx,js,jsx}`],
19
18
  skipFormat: true,
19
+ addPlugin: options.addPlugin,
20
20
  });
21
21
  if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
22
22
  (0, eslint_file_1.addExtendsToLintConfig)(host, options.e2eProjectRoot, 'plugin:@nx/react');
@@ -4,11 +4,15 @@ exports.addProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const get_targets_1 = require("./get-targets");
6
6
  function addProject(host, options) {
7
+ const nxJson = (0, devkit_1.readNxJson)(host);
8
+ const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
9
+ ? p === '@nx/detox/plugin'
10
+ : p.plugin === '@nx/detox/plugin');
7
11
  (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
8
12
  root: options.e2eProjectRoot,
9
13
  sourceRoot: `${options.e2eProjectRoot}/src`,
10
14
  projectType: 'application',
11
- targets: { ...getTargets(options) },
15
+ targets: hasPlugin ? {} : getTargets(options),
12
16
  tags: [],
13
17
  implicitDependencies: [options.appProject],
14
18
  });
@@ -0,0 +1,3 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { NormalizedSchema } from './normalize-options';
3
+ export declare function ensureDependencies(tree: Tree, options: NormalizedSchema): import("@nx/devkit").GeneratorCallback;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("@nx/jest/src/utils/versions");
6
+ const versions_2 = require("../../../utils/versions");
7
+ function ensureDependencies(tree, options) {
8
+ const devDependencies = {
9
+ '@testing-library/jest-dom': versions_2.testingLibraryJestDom,
10
+ '@types/node': versions_1.typesNodeVersion,
11
+ 'jest-circus': versions_1.jestVersion,
12
+ };
13
+ if (options.framework === 'expo') {
14
+ devDependencies['@config-plugins/detox'] = versions_2.configPluginsDetoxVersion;
15
+ }
16
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
17
+ }
18
+ exports.ensureDependencies = ensureDependencies;
@@ -11,6 +11,10 @@ async function normalizeOptions(host, options) {
11
11
  projectNameAndRootFormat: options.projectNameAndRootFormat,
12
12
  callingGenerator: '@nx/detox:application',
13
13
  });
14
+ const nxJson = (0, devkit_1.readNxJson)(host);
15
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
16
+ nxJson.useInferencePlugins !== false;
17
+ options.addPlugin ??= addPlugin;
14
18
  const { fileName: appFileName, className: appClassName } = (0, devkit_1.names)(options.appName || options.appProject);
15
19
  const { root: appRoot } = (0, devkit_1.readProjectConfiguration)(host, (0, devkit_1.names)(options.appProject).fileName);
16
20
  return {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "title": "Create Detox Configuration for the workspace",
4
4
  "description": "Create Detox Configuration for the workspace.",
5
5
  "type": "object",
@@ -1,5 +1,6 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function detoxInitGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export declare function detoxInitGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
5
  export declare function updateDependencies(host: Tree, schema: Schema): GeneratorCallback;
5
6
  export default detoxInitGenerator;
@@ -1,35 +1,64 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateDependencies = exports.detoxInitGenerator = void 0;
3
+ exports.updateDependencies = exports.detoxInitGeneratorInternal = exports.detoxInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const versions_1 = require("@nx/jest/src/utils/versions");
6
- const versions_2 = require("../../utils/versions");
7
- async function detoxInitGenerator(host, schema) {
5
+ const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
+ const plugin_1 = require("../../plugins/plugin");
7
+ const versions_1 = require("../../utils/versions");
8
+ function detoxInitGenerator(host, schema) {
9
+ return detoxInitGeneratorInternal(host, { addPlugin: false, ...schema });
10
+ }
11
+ exports.detoxInitGenerator = detoxInitGenerator;
12
+ async function detoxInitGeneratorInternal(host, schema) {
8
13
  const tasks = [];
14
+ const nxJson = (0, devkit_1.readNxJson)(host);
15
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
16
+ nxJson.useInferencePlugins !== false;
17
+ schema.addPlugin ??= addPluginDefault;
9
18
  if (!schema.skipPackageJson) {
10
19
  tasks.push(moveDependency(host));
11
20
  tasks.push(updateDependencies(host, schema));
12
21
  }
22
+ if (schema.addPlugin) {
23
+ addPlugin(host);
24
+ }
25
+ if (schema.updatePackageScripts) {
26
+ await (0, update_package_scripts_1.updatePackageScripts)(host, plugin_1.createNodes);
27
+ }
13
28
  if (!schema.skipFormat) {
14
29
  await (0, devkit_1.formatFiles)(host);
15
30
  }
16
31
  return (0, devkit_1.runTasksInSerial)(...tasks);
17
32
  }
18
- exports.detoxInitGenerator = detoxInitGenerator;
33
+ exports.detoxInitGeneratorInternal = detoxInitGeneratorInternal;
19
34
  function updateDependencies(host, schema) {
20
35
  return (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
21
- '@nx/detox': versions_2.nxVersion,
22
- detox: versions_2.detoxVersion,
23
- '@testing-library/jest-dom': versions_2.testingLibraryJestDom,
24
- '@types/node': versions_1.typesNodeVersion,
25
- 'jest-circus': versions_1.jestVersion,
26
- ...(schema.framework === 'expo'
27
- ? { '@config-plugins/detox': versions_2.configPluginsDetoxVersion }
28
- : {}),
29
- });
36
+ '@nx/detox': versions_1.nxVersion,
37
+ detox: versions_1.detoxVersion,
38
+ }, undefined, schema.keepExistingVersions);
30
39
  }
31
40
  exports.updateDependencies = updateDependencies;
32
41
  function moveDependency(host) {
33
42
  return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/detox'], []);
34
43
  }
44
+ function addPlugin(host) {
45
+ const nxJson = (0, devkit_1.readNxJson)(host);
46
+ nxJson.plugins ??= [];
47
+ for (const plugin of nxJson.plugins) {
48
+ if (typeof plugin === 'string'
49
+ ? plugin === '@nx/detox/plugin'
50
+ : plugin.plugin === '@nx/detox/plugin') {
51
+ return;
52
+ }
53
+ }
54
+ nxJson.plugins.push({
55
+ plugin: '@nx/detox/plugin',
56
+ options: {
57
+ buildTargetName: 'build',
58
+ startTargetName: 'start',
59
+ testTargetName: 'test',
60
+ },
61
+ });
62
+ (0, devkit_1.updateNxJson)(host, nxJson);
63
+ }
35
64
  exports.default = detoxInitGenerator;
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "title": "Add Detox Schematics",
4
4
  "description": "Add Detox Schematics.",
5
5
  "type": "object",
@@ -16,11 +16,17 @@
16
16
  "description": "Do not add dependencies to `package.json`.",
17
17
  "x-priority": "internal"
18
18
  },
19
- "framework": {
20
- "type": "string",
21
- "description": "App framework to test",
22
- "enum": ["react-native", "expo"],
23
- "default": "react-native"
19
+ "keepExistingVersions": {
20
+ "type": "boolean",
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
+ },
25
+ "updatePackageScripts": {
26
+ "type": "boolean",
27
+ "x-priority": "internal",
28
+ "description": "Update `package.json` scripts with inferred targets",
29
+ "default": false
24
30
  }
25
31
  },
26
32
  "required": []
@@ -0,0 +1,8 @@
1
+ import { CreateDependencies, CreateNodes } from '@nx/devkit';
2
+ export interface DetoxPluginOptions {
3
+ buildTargetName?: string;
4
+ startTargetName?: string;
5
+ testTargetName?: string;
6
+ }
7
+ export declare const createDependencies: CreateDependencies;
8
+ export declare const createNodes: CreateNodes<DetoxPluginOptions>;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodes = exports.createDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const js_1 = require("@nx/js");
7
+ const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
+ const fs_1 = require("fs");
9
+ const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
10
+ const cache_directory_1 = require("nx/src/utils/cache-directory");
11
+ const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'detox.hash');
12
+ const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
13
+ const calculatedTargets = {};
14
+ function readTargetsCache() {
15
+ return (0, devkit_1.readJsonFile)(cachePath);
16
+ }
17
+ function writeTargetsToCache(targets) {
18
+ (0, devkit_1.writeJsonFile)(cachePath, targets);
19
+ }
20
+ const createDependencies = () => {
21
+ writeTargetsToCache(calculatedTargets);
22
+ return [];
23
+ };
24
+ exports.createDependencies = createDependencies;
25
+ exports.createNodes = [
26
+ '**/{detox.config,.detoxrc}.{json,js}',
27
+ (configFilePath, options, context) => {
28
+ options = normalizeOptions(options);
29
+ const projectRoot = (0, path_1.dirname)(configFilePath);
30
+ // Do not create a project if project.json isn't there.
31
+ const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
32
+ if (!siblingFiles.includes('project.json')) {
33
+ return {};
34
+ }
35
+ const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
36
+ (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
37
+ ]);
38
+ const targets = targetsCache[hash]
39
+ ? targetsCache[hash]
40
+ : buildDetoxTargets(projectRoot, options, context);
41
+ calculatedTargets[hash] = targets;
42
+ return {
43
+ projects: {
44
+ [projectRoot]: {
45
+ targets,
46
+ },
47
+ },
48
+ };
49
+ },
50
+ ];
51
+ function buildDetoxTargets(projectRoot, options, context) {
52
+ const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
53
+ const targets = {
54
+ [options.buildTargetName]: {
55
+ command: `detox build`,
56
+ options: { cwd: projectRoot },
57
+ cache: true,
58
+ inputs: getInputs(namedInputs),
59
+ },
60
+ [options.startTargetName]: {
61
+ command: `detox start`,
62
+ options: { cwd: projectRoot },
63
+ },
64
+ [options.testTargetName]: {
65
+ command: `detox test`,
66
+ options: { cwd: projectRoot },
67
+ cache: true,
68
+ inputs: getInputs(namedInputs),
69
+ },
70
+ };
71
+ return targets;
72
+ }
73
+ function getInputs(namedInputs) {
74
+ return [
75
+ ...('production' in namedInputs
76
+ ? ['default', '^production']
77
+ : ['default', '^default']),
78
+ {
79
+ externalDependencies: ['detox'],
80
+ },
81
+ ];
82
+ }
83
+ function normalizeOptions(options) {
84
+ options ??= {};
85
+ options.buildTargetName ??= 'build';
86
+ options.startTargetName ??= 'start';
87
+ options.testTargetName ??= 'test';
88
+ return options;
89
+ }
@@ -1,4 +1,4 @@
1
1
  export declare const nxVersion: any;
2
- export declare const detoxVersion = "^20.11.1";
3
- export declare const testingLibraryJestDom = "5.16.5";
4
- export declare const configPluginsDetoxVersion = "~6.0.0";
2
+ export declare const detoxVersion = "~20.18.1";
3
+ export declare const testingLibraryJestDom = "~6.4.2";
4
+ export declare const configPluginsDetoxVersion = "~7.0.0";
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configPluginsDetoxVersion = exports.testingLibraryJestDom = exports.detoxVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
- exports.detoxVersion = '^20.11.1';
6
- exports.testingLibraryJestDom = '5.16.5';
7
- exports.configPluginsDetoxVersion = '~6.0.0'; // only required for expo
5
+ exports.detoxVersion = '~20.18.1';
6
+ exports.testingLibraryJestDom = '~6.4.2';
7
+ exports.configPluginsDetoxVersion = '~7.0.0'; // only required for expo