This repository has been archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support to display svg for react-native
- Loading branch information
Showing
14 changed files
with
346 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 29 additions & 18 deletions
47
packages/react-native/src/generators/application/files/app/metro.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
const { withNxMetro } = require('@nrwl/react-native'); | ||
const { getDefaultConfig } = require('metro-config'); | ||
|
||
module.exports = withNxMetro( | ||
{ | ||
transformer: { | ||
getTransformOptions: async () => ({ | ||
transform: { | ||
experimentalImportSupport: false, | ||
inlineRequires: true, | ||
}, | ||
}), | ||
module.exports = (async () => { | ||
const { | ||
resolver: { sourceExts, assetExts }, | ||
} = await getDefaultConfig(); | ||
return withNxMetro( | ||
{ | ||
transformer: { | ||
getTransformOptions: async () => ({ | ||
transform: { | ||
experimentalImportSupport: false, | ||
inlineRequires: true, | ||
}, | ||
}), | ||
babelTransformerPath: require.resolve('react-native-svg-transformer'), | ||
}, | ||
resolver: { | ||
assetExts: assetExts.filter((ext) => ext !== 'svg'), | ||
sourceExts: [...sourceExts, 'svg'], | ||
}, | ||
}, | ||
}, | ||
{ | ||
// Change this to true to see debugging info. | ||
// Useful if you have issues resolving modules | ||
debug: false, | ||
// all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' | ||
extensions: [], | ||
} | ||
); | ||
{ | ||
// Change this to true to see debugging info. | ||
// Useful if you have issues resolving modules | ||
debug: false, | ||
// all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' | ||
extensions: [], | ||
} | ||
); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/react-native/src/generators/application/files/app/src/app/star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
...es/react-native/src/migrations/update-12-4-0/add-react-native-codegen-dev-dependencies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
packages/react-native/src/migrations/update-12-4-0/add-react-native-svg.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { readJson, Tree } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { Linter } from '@nrwl/linter'; | ||
import { addProject } from '../../generators/application/lib/add-project'; | ||
import { normalizeOptions } from '../../generators/application/lib/normalize-options'; | ||
import { | ||
reactNativeSvgTransformerVersion, | ||
reactNativeSvgVersion, | ||
} from '../../utils/versions'; | ||
import update from './add-react-native-svg'; | ||
|
||
describe('Add react-native-svg to dev dependencies 12.4.0', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(async () => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it(`should update libs if dependencies contain react-native`, async () => { | ||
tree.write( | ||
'package.json', | ||
JSON.stringify({ | ||
dependencies: { 'react-native': '*' }, | ||
devDependencies: {}, | ||
}) | ||
); | ||
|
||
await update(tree); | ||
const devDependencies = readJson(tree, 'package.json').devDependencies; | ||
|
||
expect(devDependencies['react-native-svg']).toEqual(reactNativeSvgVersion); | ||
expect(devDependencies['react-native-svg-transformer']).toEqual( | ||
reactNativeSvgTransformerVersion | ||
); | ||
}); | ||
|
||
it(`should not update libs if dependencies do not contain react-native`, async () => { | ||
tree.write( | ||
'package.json', | ||
JSON.stringify({ | ||
dependencies: {}, | ||
devDependencies: {}, | ||
}) | ||
); | ||
|
||
await update(tree); | ||
const devDependencies = readJson(tree, 'package.json').devDependencies; | ||
|
||
expect(devDependencies['react-native-svg']).toEqual(undefined); | ||
expect(devDependencies['react-native-svg-transformer']).toEqual(undefined); | ||
}); | ||
|
||
it(`should add react-native-svg app tsconfig.json and package.json`, async () => { | ||
tree.write( | ||
'package.json', | ||
JSON.stringify({ | ||
dependencies: { 'react-native': '*' }, | ||
devDependencies: {}, | ||
}) | ||
); | ||
addProject( | ||
tree, | ||
normalizeOptions(tree, { | ||
name: 'myApp', | ||
displayName: 'myApp', | ||
linter: Linter.EsLint, | ||
e2eTestRunner: 'none', | ||
}) | ||
); | ||
tree.write('apps/my-app/tsconfig.json', '{}'); | ||
tree.write( | ||
'apps/my-app/package.json', | ||
JSON.stringify({ | ||
dependencies: {}, | ||
}) | ||
); | ||
|
||
await update(tree); | ||
|
||
const tsconfig = readJson(tree, 'apps/my-app/tsconfig.json'); | ||
expect(tsconfig.files).toEqual([ | ||
'../../node_modules/@nrwl/react-native/typings/image.d.ts', | ||
]); | ||
|
||
const packageJson = readJson(tree, 'apps/my-app/package.json'); | ||
expect(packageJson.dependencies).toEqual({ 'react-native-svg': '*' }); | ||
}); | ||
|
||
it(`should not add react-native-svg app tsconfig.json and package.json if files do not exist`, async () => { | ||
tree.write( | ||
'package.json', | ||
JSON.stringify({ | ||
dependencies: { 'react-native': '*' }, | ||
devDependencies: {}, | ||
}) | ||
); | ||
addProject( | ||
tree, | ||
normalizeOptions(tree, { | ||
name: 'myApp', | ||
displayName: 'myApp', | ||
linter: Linter.EsLint, | ||
e2eTestRunner: 'none', | ||
}) | ||
); | ||
|
||
await update(tree); | ||
|
||
expect(() => readJson(tree, 'apps/my-app/tsconfig.json')).toThrow(); | ||
expect(() => readJson(tree, 'apps/my-app/package.json')).toThrow(); | ||
}); | ||
}); |
Oops, something went wrong.