@nx/react-native 16.10.0 → 17.0.0-beta.1
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/migrations.json +0 -972
- package/package.json +9 -9
- package/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.d.ts +0 -8
- package/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.js +0 -57
- package/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.spec.ts +0 -79
- package/src/migrations/update-12-5-0/update-jest-for-react-native.d.ts +0 -2
- package/src/migrations/update-12-5-0/update-jest-for-react-native.js +0 -58
- package/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.d.ts +0 -2
- package/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.js +0 -18
- package/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.spec.ts +0 -48
- package/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.d.ts +0 -6
- package/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.js +0 -36
- package/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.spec.ts +0 -61
- package/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.d.ts +0 -6
- package/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.js +0 -28
- package/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts +0 -192
- package/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.d.ts +0 -5
- package/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.js +0 -33
- package/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.spec.ts +0 -84
- package/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.d.ts +0 -5
- package/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.js +0 -37
- package/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.spec.ts +0 -48
- package/src/migrations/update-14-2-1/rename-blockList-metro-config.d.ts +0 -6
- package/src/migrations/update-14-2-1/rename-blockList-metro-config.js +0 -28
- package/src/migrations/update-14-2-1/rename-blockList-metro-config.spec.ts +0 -190
- package/src/migrations/update-14-5-5/add-exclude-sync-deps.d.ts +0 -5
- package/src/migrations/update-14-5-5/add-exclude-sync-deps.js +0 -21
- package/src/migrations/update-14-5-5/add-exclude-sync-deps.spec.ts +0 -39
- package/src/migrations/update-14-5-8/change-searchDir-storybook.d.ts +0 -5
- package/src/migrations/update-14-5-8/change-searchDir-storybook.js +0 -21
- package/src/migrations/update-14-5-8/change-searchDir-storybook.spec.ts +0 -39
- package/src/migrations/update-14-6-0/remove-jest-transform.d.ts +0 -5
- package/src/migrations/update-14-6-0/remove-jest-transform.js +0 -53
- package/src/migrations/update-14-6-0/remove-jest-transform.spec.ts +0 -109
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for React Native contains generators for managing React Native applications and libraries within an Nx workspace. It provides: \n\n-Integration with libraries such as Jest, Detox, and Storybook.\n-Scaffolding for creating buildable libraries that can be published to npm.\n-Utilities for automatic workspace refactoring.",
|
|
6
6
|
"keywords": [
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"node-fetch": "^2.6.7",
|
|
37
37
|
"tsconfig-paths": "^4.1.2",
|
|
38
38
|
"tslib": "^2.3.0",
|
|
39
|
-
"@nx/detox": "
|
|
40
|
-
"@nx/devkit": "
|
|
41
|
-
"@nx/jest": "
|
|
42
|
-
"@nx/js": "
|
|
43
|
-
"@nx/linter": "
|
|
44
|
-
"@nx/react": "
|
|
45
|
-
"@nx/workspace": "
|
|
46
|
-
"@nrwl/react-native": "
|
|
39
|
+
"@nx/detox": "17.0.0-beta.1",
|
|
40
|
+
"@nx/devkit": "17.0.0-beta.1",
|
|
41
|
+
"@nx/jest": "17.0.0-beta.1",
|
|
42
|
+
"@nx/js": "17.0.0-beta.1",
|
|
43
|
+
"@nx/linter": "17.0.0-beta.1",
|
|
44
|
+
"@nx/react": "17.0.0-beta.1",
|
|
45
|
+
"@nx/workspace": "17.0.0-beta.1",
|
|
46
|
+
"@nrwl/react-native": "17.0.0-beta.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"react-native": ">= 0.72.0 < 0.73.0"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
2
|
-
/**
|
|
3
|
-
* Add support to display svg in react native:
|
|
4
|
-
* - Add react-native-svg-transform and react-native-svg packages to workspace's package.json.
|
|
5
|
-
* - Add typing to app's tsconfig.json.
|
|
6
|
-
* - Add react-native-svg to app's package.json.
|
|
7
|
-
*/
|
|
8
|
-
export default function update(tree: Tree): Promise<void>;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
/**
|
|
5
|
-
* Add support to display svg in react native:
|
|
6
|
-
* - Add react-native-svg-transform and react-native-svg packages to workspace's package.json.
|
|
7
|
-
* - Add typing to app's tsconfig.json.
|
|
8
|
-
* - Add react-native-svg to app's package.json.
|
|
9
|
-
*/
|
|
10
|
-
async function update(tree) {
|
|
11
|
-
const projects = (0, devkit_1.getProjects)(tree);
|
|
12
|
-
projects.forEach((project) => {
|
|
13
|
-
if (project.targets?.start?.executor !== '@nrwl/react-native:start')
|
|
14
|
-
return;
|
|
15
|
-
addReactNativeSvgToAppPackageJson(tree, project);
|
|
16
|
-
addReactNativeSvgToTsconfig(tree, project);
|
|
17
|
-
mockSvgInJestConfig(tree, project);
|
|
18
|
-
});
|
|
19
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
20
|
-
}
|
|
21
|
-
exports.default = update;
|
|
22
|
-
function addReactNativeSvgToAppPackageJson(host, project) {
|
|
23
|
-
const packageJSonPath = `${project.root}/package.json`;
|
|
24
|
-
if (!host.exists(packageJSonPath))
|
|
25
|
-
return;
|
|
26
|
-
(0, devkit_1.updateJson)(host, packageJSonPath, (json) => {
|
|
27
|
-
const dependencies = json.dependencies || {};
|
|
28
|
-
dependencies['react-native-svg'] = '*';
|
|
29
|
-
return json;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function addReactNativeSvgToTsconfig(host, project) {
|
|
33
|
-
const tsconfigPath = `${project.root}/tsconfig.json`;
|
|
34
|
-
if (!host.exists(tsconfigPath))
|
|
35
|
-
return;
|
|
36
|
-
const offset = (0, devkit_1.offsetFromRoot)(project.root);
|
|
37
|
-
(0, devkit_1.updateJson)(host, tsconfigPath, (json) => {
|
|
38
|
-
const files = json.files || [];
|
|
39
|
-
files.push(`${offset}node_modules/@nrwl/react-native/typings/svg.d.ts`);
|
|
40
|
-
json.files = files;
|
|
41
|
-
return json;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
function mockSvgInJestConfig(host, project) {
|
|
45
|
-
const jestConfigPath = project.targets?.test?.options?.jestConfig;
|
|
46
|
-
if (!jestConfigPath || !host.exists(jestConfigPath))
|
|
47
|
-
return;
|
|
48
|
-
try {
|
|
49
|
-
const contents = host.read(jestConfigPath, 'utf-8');
|
|
50
|
-
if (contents.includes('moduleNameMapper'))
|
|
51
|
-
return;
|
|
52
|
-
host.write(jestConfigPath, contents.replace(/,([^,]*)$/, `, moduleNameMapper: {'\\.svg': '@nrwl/react-native/plugins/jest/svg-mock'}, $1`));
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update ${jestConfigPath} for project ${project.root}.`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { addProjectConfiguration, readJson, Tree } from '@nx/devkit';
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
-
import {
|
|
4
|
-
reactNativeSvgTransformerVersion,
|
|
5
|
-
reactNativeSvgVersion,
|
|
6
|
-
} from '../../utils/versions';
|
|
7
|
-
import update from './add-react-native-svg-12-10-0';
|
|
8
|
-
|
|
9
|
-
describe('Add react-native-svg to dev dependencies', () => {
|
|
10
|
-
let tree: Tree;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
14
|
-
addProjectConfiguration(tree, 'products', {
|
|
15
|
-
root: 'apps/products',
|
|
16
|
-
sourceRoot: 'apps/products/src',
|
|
17
|
-
targets: {
|
|
18
|
-
start: {
|
|
19
|
-
executor: '@nrwl/react-native:start',
|
|
20
|
-
options: {
|
|
21
|
-
port: 8081,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
test: {
|
|
25
|
-
executor: '@nrwl/jest:jest',
|
|
26
|
-
options: {
|
|
27
|
-
jestConfig: 'apps/products/jest.config.js',
|
|
28
|
-
passWithNoTests: true,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it(`should add react-native-svg to app's tsconfig.json and package.json`, async () => {
|
|
36
|
-
tree.write('apps/products/tsconfig.json', '{}');
|
|
37
|
-
tree.write(
|
|
38
|
-
'apps/products/package.json',
|
|
39
|
-
JSON.stringify({
|
|
40
|
-
dependencies: {},
|
|
41
|
-
})
|
|
42
|
-
);
|
|
43
|
-
tree.write(
|
|
44
|
-
'apps/products/jest.config.js',
|
|
45
|
-
`module.exports = {
|
|
46
|
-
preset: 'react-native',
|
|
47
|
-
};`
|
|
48
|
-
);
|
|
49
|
-
await update(tree);
|
|
50
|
-
|
|
51
|
-
const tsconfig = readJson(tree, 'apps/products/tsconfig.json');
|
|
52
|
-
expect(tsconfig.files).toEqual([
|
|
53
|
-
'../../node_modules/@nrwl/react-native/typings/svg.d.ts',
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
const packageJson = readJson(tree, 'apps/products/package.json');
|
|
57
|
-
expect(packageJson.dependencies).toEqual({ 'react-native-svg': '*' });
|
|
58
|
-
|
|
59
|
-
const jestConfig = tree.read('apps/products/jest.config.js', 'utf-8');
|
|
60
|
-
expect(jestConfig).toContain(
|
|
61
|
-
`moduleNameMapper: { '.svg': '@nrwl/react-native/plugins/jest/svg-mock' },`
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it(`should not add react-native-svg to app's tsconfig.json and package.json if files do not exist`, async () => {
|
|
66
|
-
tree.write(
|
|
67
|
-
'package.json',
|
|
68
|
-
JSON.stringify({
|
|
69
|
-
dependencies: { 'react-native': '*' },
|
|
70
|
-
devDependencies: {},
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
await update(tree);
|
|
75
|
-
|
|
76
|
-
expect(() => readJson(tree, 'apps/products/tsconfig.json')).toThrow();
|
|
77
|
-
expect(() => readJson(tree, 'apps/products/package.json')).toThrow();
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
/**
|
|
7
|
-
* This function update jest.config.js and test.setup.ts for react native project for Jest 27.
|
|
8
|
-
* Inside jest.config.js, remove ...workspacePreset because it has testEnvironment set as jsdom.
|
|
9
|
-
* Just set preset as react-native is sufficient.
|
|
10
|
-
* Also remove the jest.useFakeTimers() in test.setup.ts.
|
|
11
|
-
*/
|
|
12
|
-
function updateJestConfig(tree) {
|
|
13
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (options, project) => {
|
|
14
|
-
if (!options.jestConfig) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const jestConfigPath = options.jestConfig;
|
|
18
|
-
const jestConfig = require((0, path_1.join)(tree.root, jestConfigPath));
|
|
19
|
-
const testEnvironment = jestConfig.testEnvironment;
|
|
20
|
-
const preset = jestConfig.preset;
|
|
21
|
-
if (testEnvironment === 'node' || preset !== 'react-native') {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
const contents = tree.read(jestConfigPath, 'utf-8');
|
|
26
|
-
tree.write(jestConfigPath, contents
|
|
27
|
-
.replace(`...workspacePreset,`, "resolver: '@nrwl/jest/plugins/resolver',")
|
|
28
|
-
.replace(`const workspacePreset = require('../../jest.preset');`, ''));
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update jest.config.js for project ${project}.`);
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const { root } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
35
|
-
let setupTestPath;
|
|
36
|
-
if (tree.exists((0, path_1.join)(root, `test-setup.ts`))) {
|
|
37
|
-
setupTestPath = (0, path_1.join)(root, `test-setup.ts`);
|
|
38
|
-
}
|
|
39
|
-
else if (tree.exists((0, path_1.join)(root, `test-setup.js`))) {
|
|
40
|
-
setupTestPath = (0, path_1.join)(root, `test-setup.js`);
|
|
41
|
-
}
|
|
42
|
-
if (setupTestPath) {
|
|
43
|
-
const contents = tree.read(setupTestPath, 'utf-8');
|
|
44
|
-
tree.write(setupTestPath, contents
|
|
45
|
-
.replace(`jest.useFakeTimers();`, '')
|
|
46
|
-
.replace(`import { jest } from '@jest/globals';`, ''));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update test-setup for project ${project}.`);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
async function update(tree) {
|
|
55
|
-
updateJestConfig(tree);
|
|
56
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
57
|
-
}
|
|
58
|
-
exports.default = update;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
const add_babel_inputs_1 = require("@nx/js/src/utils/add-babel-inputs");
|
|
5
|
-
async function update(tree) {
|
|
6
|
-
const projects = (0, devkit_1.getProjects)(tree);
|
|
7
|
-
if (tree.exists('/babel.config.json') || tree.exists('/babel.config.js')) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const hasReactNaiveProject = Array.from(projects)
|
|
11
|
-
.map(([_, project]) => project)
|
|
12
|
-
.some((project) => project.targets?.start?.executor === '@nrwl/react-native:start');
|
|
13
|
-
if (hasReactNaiveProject) {
|
|
14
|
-
(0, add_babel_inputs_1.addBabelInputs)(tree);
|
|
15
|
-
}
|
|
16
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
17
|
-
}
|
|
18
|
-
exports.default = update;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { addProjectConfiguration, readJson, Tree } from '@nx/devkit';
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
-
import update from './add-babel-config-root-13-5-0';
|
|
4
|
-
|
|
5
|
-
describe('Add react-native-svg to dev dependencies', () => {
|
|
6
|
-
let tree: Tree;
|
|
7
|
-
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
10
|
-
addProjectConfiguration(tree, 'products', {
|
|
11
|
-
root: 'apps/products',
|
|
12
|
-
sourceRoot: 'apps/products/src',
|
|
13
|
-
targets: {
|
|
14
|
-
start: {
|
|
15
|
-
executor: '@nrwl/react-native:start',
|
|
16
|
-
options: {
|
|
17
|
-
port: 8081,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
test: {
|
|
21
|
-
executor: '@nrwl/jest:jest',
|
|
22
|
-
options: {
|
|
23
|
-
jestConfig: 'apps/products/jest.config.js',
|
|
24
|
-
passWithNoTests: true,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it(`should add babel.config.json at root`, async () => {
|
|
32
|
-
await update(tree);
|
|
33
|
-
|
|
34
|
-
const babelConfigJson = readJson(tree, 'babel.config.json');
|
|
35
|
-
expect(babelConfigJson).toEqual({
|
|
36
|
-
babelrcRoots: ['*'],
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it(`should not change babel.config.json if it already exists`, async () => {
|
|
41
|
-
tree.write('babel.config.json', '{}');
|
|
42
|
-
|
|
43
|
-
await update(tree);
|
|
44
|
-
|
|
45
|
-
const babelConfigJson = readJson(tree, 'babel.config.json');
|
|
46
|
-
expect(babelConfigJson).toEqual({});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
2
|
-
/**
|
|
3
|
-
* Update svg typings in tsconfig for react native app
|
|
4
|
-
* Replace node_modules/@nrwl/react/typings/image.d.ts with node_modules/@nrwl/react-native/typings/svg.d.ts
|
|
5
|
-
*/
|
|
6
|
-
export default function update(tree: Tree): Promise<void>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
/**
|
|
5
|
-
* Update svg typings in tsconfig for react native app
|
|
6
|
-
* Replace node_modules/@nrwl/react/typings/image.d.ts with node_modules/@nrwl/react-native/typings/svg.d.ts
|
|
7
|
-
*/
|
|
8
|
-
async function update(tree) {
|
|
9
|
-
const projects = (0, devkit_1.getProjects)(tree);
|
|
10
|
-
projects.forEach((project) => {
|
|
11
|
-
if (project.targets?.start?.executor !== '@nrwl/react-native:start')
|
|
12
|
-
return;
|
|
13
|
-
updateReactNativeSvgTypingInTsconfig(tree, project);
|
|
14
|
-
});
|
|
15
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
16
|
-
}
|
|
17
|
-
exports.default = update;
|
|
18
|
-
function updateReactNativeSvgTypingInTsconfig(host, project) {
|
|
19
|
-
const tsconfigPath = `${project.root}/tsconfig.json`;
|
|
20
|
-
if (!host.exists(tsconfigPath))
|
|
21
|
-
return;
|
|
22
|
-
const offset = (0, devkit_1.offsetFromRoot)(project.root);
|
|
23
|
-
(0, devkit_1.updateJson)(host, tsconfigPath, (json) => {
|
|
24
|
-
const files = json.files || [];
|
|
25
|
-
const imageTypingIndex = files.findIndex((file) => file === `${offset}node_modules/@nrwl/react/typings/image.d.ts`);
|
|
26
|
-
const reactNativeSvgTypingPath = `${offset}node_modules/@nrwl/react-native/typings/svg.d.ts`;
|
|
27
|
-
if (imageTypingIndex === -1) {
|
|
28
|
-
files.push(reactNativeSvgTypingPath);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
files[imageTypingIndex] = reactNativeSvgTypingPath;
|
|
32
|
-
}
|
|
33
|
-
json.files = files;
|
|
34
|
-
return json;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { addProjectConfiguration, readJson, Tree } from '@nx/devkit';
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
-
import update from './update-react-native-typing-svg-13-5-0';
|
|
4
|
-
|
|
5
|
-
describe('Update svg typings in tsconfig for react native app', () => {
|
|
6
|
-
let tree: Tree;
|
|
7
|
-
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
10
|
-
addProjectConfiguration(tree, 'products', {
|
|
11
|
-
root: 'apps/products',
|
|
12
|
-
sourceRoot: 'apps/products/src',
|
|
13
|
-
targets: {
|
|
14
|
-
start: {
|
|
15
|
-
executor: '@nrwl/react-native:start',
|
|
16
|
-
options: {
|
|
17
|
-
port: 8081,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
test: {
|
|
21
|
-
executor: '@nrwl/jest:jest',
|
|
22
|
-
options: {
|
|
23
|
-
jestConfig: 'apps/products/jest.config.js',
|
|
24
|
-
passWithNoTests: true,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it(`should add svg typing to tsconfig.json`, async () => {
|
|
32
|
-
tree.write('apps/products/tsconfig.json', '{}');
|
|
33
|
-
await update(tree);
|
|
34
|
-
|
|
35
|
-
const tsconfig = readJson(tree, 'apps/products/tsconfig.json');
|
|
36
|
-
expect(tsconfig.files).toEqual([
|
|
37
|
-
'../../node_modules/@nrwl/react-native/typings/svg.d.ts',
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it(`should update to svg typing in tsconfig.json if image typing from react exists`, async () => {
|
|
42
|
-
tree.write(
|
|
43
|
-
'apps/products/tsconfig.json',
|
|
44
|
-
`{
|
|
45
|
-
"files": ["../../node_modules/@nrwl/react/typings/image.d.ts"]
|
|
46
|
-
}`
|
|
47
|
-
);
|
|
48
|
-
await update(tree);
|
|
49
|
-
|
|
50
|
-
const tsconfig = readJson(tree, 'apps/products/tsconfig.json');
|
|
51
|
-
expect(tsconfig.files).toEqual([
|
|
52
|
-
'../../node_modules/@nrwl/react-native/typings/svg.d.ts',
|
|
53
|
-
]);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it(`should update app's tsconfig.json and package.json if file does not exist`, async () => {
|
|
57
|
-
await update(tree);
|
|
58
|
-
|
|
59
|
-
expect(() => readJson(tree, 'apps/products/tsconfig.json')).toThrow();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
/**
|
|
5
|
-
* Add projectRoot and watchFolders options in metro.config.js
|
|
6
|
-
* @param tree
|
|
7
|
-
*/
|
|
8
|
-
async function update(tree) {
|
|
9
|
-
const projects = (0, devkit_1.getProjects)(tree);
|
|
10
|
-
projects.forEach((project) => {
|
|
11
|
-
const metroConfigPath = `${project.root}/metro.config.js`;
|
|
12
|
-
if (project.targets?.start?.executor !== '@nrwl/react-native:start' ||
|
|
13
|
-
!tree.exists(metroConfigPath))
|
|
14
|
-
return;
|
|
15
|
-
try {
|
|
16
|
-
const metroConfigContent = tree.read(metroConfigPath, 'utf-8');
|
|
17
|
-
if (metroConfigContent.includes('projectRoot: __dirname')) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
tree.write(metroConfigPath, metroConfigContent.replace('debug: ', 'projectRoot: __dirname, watchFolders: [], debug: '));
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update ${metroConfigPath} for project ${project.root}.`);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
27
|
-
}
|
|
28
|
-
exports.default = update;
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { addProjectConfiguration, Tree } from '@nx/devkit';
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
-
|
|
4
|
-
import update from './add-project-root-metro-config-14-0-0';
|
|
5
|
-
|
|
6
|
-
describe('Add projectRoot option in metro.config.js', () => {
|
|
7
|
-
let tree: Tree;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
11
|
-
addProjectConfiguration(tree, 'products', {
|
|
12
|
-
root: 'apps/products',
|
|
13
|
-
sourceRoot: 'apps/products/src',
|
|
14
|
-
targets: {
|
|
15
|
-
start: {
|
|
16
|
-
executor: '@nrwl/react-native:start',
|
|
17
|
-
options: {
|
|
18
|
-
port: 8081,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it(`should update metro.config.js and add key projectRoot`, async () => {
|
|
26
|
-
tree.write(
|
|
27
|
-
'apps/products/metro.config.js',
|
|
28
|
-
`
|
|
29
|
-
const { withNxMetro } = require('@nx/react-native');
|
|
30
|
-
const { getDefaultConfig } = require('metro-config');
|
|
31
|
-
|
|
32
|
-
module.exports = (async () => {
|
|
33
|
-
const {
|
|
34
|
-
resolver: { sourceExts, assetExts },
|
|
35
|
-
} = await getDefaultConfig();
|
|
36
|
-
// console.log(getModulesRunBeforeMainModule);
|
|
37
|
-
return withNxMetro(
|
|
38
|
-
{
|
|
39
|
-
transformer: {
|
|
40
|
-
getTransformOptions: async () => ({
|
|
41
|
-
transform: {
|
|
42
|
-
experimentalImportSupport: false,
|
|
43
|
-
inlineRequires: true,
|
|
44
|
-
},
|
|
45
|
-
}),
|
|
46
|
-
babelTransformerPath: require.resolve('react-native-svg-transformer'),
|
|
47
|
-
},
|
|
48
|
-
resolver: {
|
|
49
|
-
assetExts: assetExts.filter((ext) => ext !== 'svg'),
|
|
50
|
-
sourceExts: [...sourceExts, 'svg'],
|
|
51
|
-
resolverMainFields: ['sbmodern', 'browser', 'main'],
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
// Change this to true to see debugging info.
|
|
56
|
-
// Useful if you have issues resolving modules
|
|
57
|
-
debug: false,
|
|
58
|
-
// all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx'
|
|
59
|
-
extensions: [],
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
})();
|
|
63
|
-
`
|
|
64
|
-
);
|
|
65
|
-
await update(tree);
|
|
66
|
-
|
|
67
|
-
expect(tree.read('apps/products/metro.config.js', 'utf-8'))
|
|
68
|
-
.toMatchInlineSnapshot(`
|
|
69
|
-
"const { withNxMetro } = require('@nx/react-native');
|
|
70
|
-
const { getDefaultConfig } = require('metro-config');
|
|
71
|
-
|
|
72
|
-
module.exports = (async () => {
|
|
73
|
-
const {
|
|
74
|
-
resolver: { sourceExts, assetExts },
|
|
75
|
-
} = await getDefaultConfig();
|
|
76
|
-
// console.log(getModulesRunBeforeMainModule);
|
|
77
|
-
return withNxMetro(
|
|
78
|
-
{
|
|
79
|
-
transformer: {
|
|
80
|
-
getTransformOptions: async () => ({
|
|
81
|
-
transform: {
|
|
82
|
-
experimentalImportSupport: false,
|
|
83
|
-
inlineRequires: true,
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
86
|
-
babelTransformerPath: require.resolve('react-native-svg-transformer'),
|
|
87
|
-
},
|
|
88
|
-
resolver: {
|
|
89
|
-
assetExts: assetExts.filter((ext) => ext !== 'svg'),
|
|
90
|
-
sourceExts: [...sourceExts, 'svg'],
|
|
91
|
-
resolverMainFields: ['sbmodern', 'browser', 'main'],
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
// Change this to true to see debugging info.
|
|
96
|
-
// Useful if you have issues resolving modules
|
|
97
|
-
projectRoot: __dirname,
|
|
98
|
-
watchFolders: [],
|
|
99
|
-
debug: false,
|
|
100
|
-
// all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx'
|
|
101
|
-
extensions: [],
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
})();
|
|
105
|
-
"
|
|
106
|
-
`);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it(`should not udpate metro.config.js if projectRoot already exists`, async () => {
|
|
110
|
-
tree.write(
|
|
111
|
-
'apps/products/metro.config.js',
|
|
112
|
-
`
|
|
113
|
-
const { withNxMetro } = require('@nx/react-native');
|
|
114
|
-
const { getDefaultConfig } = require('metro-config');
|
|
115
|
-
|
|
116
|
-
module.exports = (async () => {
|
|
117
|
-
const {
|
|
118
|
-
resolver: { sourceExts, assetExts },
|
|
119
|
-
} = await getDefaultConfig();
|
|
120
|
-
// console.log(getModulesRunBeforeMainModule);
|
|
121
|
-
return withNxMetro(
|
|
122
|
-
{
|
|
123
|
-
transformer: {
|
|
124
|
-
getTransformOptions: async () => ({
|
|
125
|
-
transform: {
|
|
126
|
-
experimentalImportSupport: false,
|
|
127
|
-
inlineRequires: true,
|
|
128
|
-
},
|
|
129
|
-
}),
|
|
130
|
-
babelTransformerPath: require.resolve('react-native-svg-transformer'),
|
|
131
|
-
},
|
|
132
|
-
resolver: {
|
|
133
|
-
assetExts: assetExts.filter((ext) => ext !== 'svg'),
|
|
134
|
-
sourceExts: [...sourceExts, 'svg'],
|
|
135
|
-
resolverMainFields: ['sbmodern', 'browser', 'main'],
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
projectRoot: __dirname,
|
|
140
|
-
// Change this to true to see debugging info.
|
|
141
|
-
// Useful if you have issues resolving modules
|
|
142
|
-
debug: false,
|
|
143
|
-
// all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx'
|
|
144
|
-
extensions: [],
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
})();
|
|
148
|
-
`
|
|
149
|
-
);
|
|
150
|
-
await update(tree);
|
|
151
|
-
|
|
152
|
-
expect(tree.read('apps/products/metro.config.js', 'utf-8'))
|
|
153
|
-
.toMatchInlineSnapshot(`
|
|
154
|
-
"const { withNxMetro } = require('@nx/react-native');
|
|
155
|
-
const { getDefaultConfig } = require('metro-config');
|
|
156
|
-
|
|
157
|
-
module.exports = (async () => {
|
|
158
|
-
const {
|
|
159
|
-
resolver: { sourceExts, assetExts },
|
|
160
|
-
} = await getDefaultConfig();
|
|
161
|
-
// console.log(getModulesRunBeforeMainModule);
|
|
162
|
-
return withNxMetro(
|
|
163
|
-
{
|
|
164
|
-
transformer: {
|
|
165
|
-
getTransformOptions: async () => ({
|
|
166
|
-
transform: {
|
|
167
|
-
experimentalImportSupport: false,
|
|
168
|
-
inlineRequires: true,
|
|
169
|
-
},
|
|
170
|
-
}),
|
|
171
|
-
babelTransformerPath: require.resolve('react-native-svg-transformer'),
|
|
172
|
-
},
|
|
173
|
-
resolver: {
|
|
174
|
-
assetExts: assetExts.filter((ext) => ext !== 'svg'),
|
|
175
|
-
sourceExts: [...sourceExts, 'svg'],
|
|
176
|
-
resolverMainFields: ['sbmodern', 'browser', 'main'],
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
projectRoot: __dirname,
|
|
181
|
-
// Change this to true to see debugging info.
|
|
182
|
-
// Useful if you have issues resolving modules
|
|
183
|
-
debug: false,
|
|
184
|
-
// all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx'
|
|
185
|
-
extensions: [],
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
})();
|
|
189
|
-
"
|
|
190
|
-
`);
|
|
191
|
-
});
|
|
192
|
-
});
|