Skip to content

Commit ca58e0a

Browse files
davidaurelioFacebook Github Bot
authored and
Facebook Github Bot
committed
BREAKING kill deprecated asset support
Summary: This removes support for `require('image!…')`, which has been deprecated for a long time. It is still possible to use images that are already bundled by the native app using the `nativeImageSource` module. Check http://facebook.github.io/react-native/docs/images.html for detailed documentation. Reviewed By: matryoshcow Differential Revision: D4231208 fbshipit-source-id: 05ec4c1ca0fabdc3fbb652f8ad1acdf240a67955
1 parent 0c50a5b commit ca58e0a

27 files changed

+18
-724
lines changed

.flowconfig

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ experimental.strict_type_args=true
3333

3434
munge_underscores=true
3535

36-
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
3736
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
3837

3938
suppress_type=$FlowIssue

Libraries/Image/GlobalImageStub.js

-24
This file was deleted.

jest-preset.json

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
]
88
},
99
"moduleNameMapper": {
10-
"^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
1110
"^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|png|psd|svg|webp)$": "RelativeImageStub",
1211
"^React$": "<rootDir>node_modules/react"
1312
},

local-cli/bundle/buildBundle.js

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
5151
const options = {
5252
projectRoots: config.getProjectRoots(),
5353
assetExts: defaultAssetExts.concat(assetExts),
54-
assetRoots: config.getAssetRoots(),
5554
blacklistRE: config.getBlacklistRE(),
5655
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
5756
transformModulePath: transformModulePath,

local-cli/bundle/saveAssets.js

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function saveAssets(
3131

3232
const filesToCopy = Object.create(null); // Map src -> dest
3333
assets
34-
.filter(asset => !asset.deprecated)
3534
.forEach(asset =>
3635
asset.scales.forEach((scale, idx) => {
3736
const src = asset.files[idx];

local-cli/default.config.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,11 @@ var rnpmConfig = require('./core/config');
2020
* to tweak.
2121
*/
2222
var config = {
23-
getProjectRoots() {
24-
return getRoots();
25-
},
23+
getProjectRoots,
2624

2725
getProjectConfig: rnpmConfig.getProjectConfig,
2826
getDependencyConfig: rnpmConfig.getDependencyConfig,
2927

30-
/**
31-
* Specify where to look for assets that are referenced using
32-
* `image!<image_name>`. Asset directories for images referenced using
33-
* `./<image.extension>` don't require any entry in here.
34-
*/
35-
getAssetRoots() {
36-
return getRoots();
37-
},
38-
3928
/**
4029
* Specify any additional asset extentions to be used by the packager.
4130
* For example, if you want to include a .ttf file, you would return ['ttf']
@@ -62,7 +51,7 @@ var config = {
6251
},
6352
};
6453

65-
function getRoots() {
54+
function getProjectRoots() {
6655
var root = process.env.REACT_NATIVE_APP_ROOT;
6756
if (root) {
6857
return [path.resolve(root)];

local-cli/dependencies/dependencies.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function dependencies(argv, config, args, packagerInstance) {
2727

2828
const packageOpts = {
2929
projectRoots: config.getProjectRoots(),
30-
assetRoots: config.getAssetRoots(),
3130
blacklistRE: config.getBlacklistRE(),
3231
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
3332
transformModulePath: transformModulePath,

local-cli/server/runServer.js

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ function getPackagerServer(args, config) {
8787

8888
return ReactPackager.createServer({
8989
assetExts: defaultAssetExts.concat(args.assetExts),
90-
assetRoots: args.assetRoots,
9190
blacklistRE: config.getBlacklistRE(),
9291
cacheVersion: '3',
9392
extraNodeModules: config.extraNodeModules,

local-cli/server/server.js

-5
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ module.exports = {
9191
description: 'override the root(s) to be used by the packager',
9292
parse: (val) => val.split(','),
9393
default: (config) => config.getProjectRoots(),
94-
}, {
95-
command: '--assetRoots [list]',
96-
description: 'specify the root directories of app assets',
97-
parse: (val) => val.split(',').map(dir => path.resolve(process.cwd(), dir)),
98-
default: (config) => config.getAssetRoots(),
9994
}, {
10095
command: '--assetExts [list]',
10196
description: 'Specify any additional asset extentions to be used by the packager',

local-cli/server/util/attachHMRServer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function attachHMRServer({httpServer, path, packagerServer}) {
4747
// `{path: '/a/b/c.js', deps: ['modA', 'modB', ...]}`
4848
return Promise.all(Object.values(response.dependencies).map(dep => {
4949
return dep.getName().then(depName => {
50-
if (dep.isAsset() || dep.isAsset_DEPRECATED() || dep.isJSON()) {
50+
if (dep.isAsset() || dep.isJSON()) {
5151
return Promise.resolve({path: dep.path, deps: []});
5252
}
5353
return packagerServer.getShallowDependencies({

local-cli/templates/HelloWorld/_flowconfig

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ experimental.strict_type_args=true
2828

2929
munge_underscores=true
3030

31-
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
3231
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
3332

3433
suppress_type=$FlowIssue

local-cli/util/Config.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export type ConfigT = {
2323
getTransformOptionsModulePath?: () => string,
2424
transformVariants?: () => {[name: string]: Object},
2525

26-
getAssetRoots(): Array<string>,
2726
getBlacklistRE(): RegExp,
2827
getProjectRoots(): Array<string>,
2928
};

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"timers": "fake",
2222
"moduleNameMapper": {
2323
"^React$": "<rootDir>/Libraries/react-native/React.js",
24-
"^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
2524
"^[./a-zA-Z0-9$_-]+\\.png$": "RelativeImageStub"
2625
},
2726
"testPathIgnorePatterns": [

packager/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Builds a bundle according to the provided options.
117117
#### `bundleOptions`
118118

119119
* `entryFile` string (required): the entry file of the bundle, relative to one
120-
of the asset roots.
120+
of the roots.
121121
* `dev` boolean (defaults to `true`): sets a global `__DEV__` variable
122122
which will effect how the React Native core libraries behave.
123123
* `minify` boolean: Whether to minify code and apply production optimizations.

packager/react-packager/src/Bundler/__tests__/Bundler-test.js

+3-23
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe('Bundler', function() {
3838
id,
3939
dependencies,
4040
isAsset,
41-
isAsset_DEPRECATED,
4241
isJSON,
4342
isPolyfill,
4443
resolution,
@@ -50,7 +49,6 @@ describe('Bundler', function() {
5049
getName: () => Promise.resolve(id),
5150
isJSON: () => isJSON,
5251
isAsset: () => isAsset,
53-
isAsset_DEPRECATED: () => isAsset_DEPRECATED,
5452
isPolyfill: () => isPolyfill,
5553
read: () => ({
5654
code: 'arbitrary',
@@ -100,13 +98,6 @@ describe('Bundler', function() {
10098
modules = [
10199
createModule({id: 'foo', path: '/root/foo.js', dependencies: []}),
102100
createModule({id: 'bar', path: '/root/bar.js', dependencies: []}),
103-
createModule({
104-
path: '/root/img/img.png',
105-
id: 'image!img',
106-
isAsset_DEPRECATED: true,
107-
dependencies: [],
108-
resolution: 2,
109-
}),
110101
createModule({
111102
id: 'new_image.png',
112103
path: '/root/img/new_image.png',
@@ -166,9 +157,8 @@ describe('Bundler', function() {
166157

167158
expect(ithAddedModule(0)).toEqual('/root/foo.js');
168159
expect(ithAddedModule(1)).toEqual('/root/bar.js');
169-
expect(ithAddedModule(2)).toEqual('/root/img/img.png');
170-
expect(ithAddedModule(3)).toEqual('/root/img/new_image.png');
171-
expect(ithAddedModule(4)).toEqual('/root/file.json');
160+
expect(ithAddedModule(2)).toEqual('/root/img/new_image.png');
161+
expect(ithAddedModule(3)).toEqual('/root/file.json');
172162

173163
expect(bundle.finalize.mock.calls[0]).toEqual([{
174164
runMainModule: true,
@@ -177,15 +167,6 @@ describe('Bundler', function() {
177167
}]);
178168

179169
expect(bundle.addAsset.mock.calls[0]).toEqual([{
180-
__packager_asset: true,
181-
path: '/root/img/img.png',
182-
uri: 'img',
183-
width: 25,
184-
height: 50,
185-
deprecated: true,
186-
}]);
187-
188-
expect(bundle.addAsset.mock.calls[1]).toEqual([{
189170
__packager_asset: true,
190171
fileSystemLocation: '/root/img',
191172
httpServerLocation: '/assets/img',
@@ -245,7 +226,7 @@ describe('Bundler', function() {
245226
sourceMapUrl: 'source_map_url',
246227
assetPlugins: ['mockPlugin1', 'asyncMockPlugin2'],
247228
}).then(bundle => {
248-
expect(bundle.addAsset.mock.calls[1]).toEqual([{
229+
expect(bundle.addAsset.mock.calls[0]).toEqual([{
249230
__packager_asset: true,
250231
fileSystemLocation: '/root/img',
251232
httpServerLocation: '/assets/img',
@@ -334,7 +315,6 @@ describe('Bundler', function() {
334315
.then((paths) => expect(paths).toEqual([
335316
'/root/foo.js',
336317
'/root/bar.js',
337-
'/root/img/img.png',
338318
'/root/img/new_image.png',
339319
'/root/img/new_image@2x.png',
340320
'/root/img/new_image@3x.png',

packager/react-packager/src/Bundler/index.js

+1-42
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ const validateOpts = declareOpts({
7979
type: 'object',
8080
required: false,
8181
},
82-
assetRoots: {
83-
type: 'array',
84-
required: false,
85-
},
8682
assetExts: {
8783
type: 'array',
8884
default: ['png'],
@@ -120,7 +116,6 @@ type Options = {
120116
resetCache: boolean,
121117
transformModulePath: string,
122118
extraNodeModules: {},
123-
assetRoots: Array<string>,
124119
assetExts: Array<string>,
125120
watch: boolean,
126121
assetServer: AssetServer,
@@ -182,7 +177,6 @@ class Bundler {
182177

183178
this._resolver = new Resolver({
184179
assetExts: opts.assetExts,
185-
assetRoots: opts.assetRoots,
186180
blacklistRE: opts.blacklistRE,
187181
cache: this._cache,
188182
extraNodeModules: opts.extraNodeModules,
@@ -603,10 +597,7 @@ class Bundler {
603597
let moduleTransport;
604598
const moduleId = getModuleId(module);
605599

606-
if (module.isAsset_DEPRECATED()) {
607-
moduleTransport =
608-
this._generateAssetModule_DEPRECATED(bundle, module, moduleId);
609-
} else if (module.isAsset()) {
600+
if (module.isAsset()) {
610601
moduleTransport = this._generateAssetModule(
611602
bundle, module, moduleId, assetPlugins, transformOptions.platform);
612603
}
@@ -639,38 +630,6 @@ class Bundler {
639630
});
640631
}
641632

642-
_generateAssetModule_DEPRECATED(bundle, module, moduleId) {
643-
return Promise.all([
644-
sizeOf(module.path),
645-
module.getName(),
646-
]).then(([dimensions, id]) => {
647-
const img = {
648-
__packager_asset: true,
649-
path: module.path,
650-
uri: id.replace(/^[^!]+!/, ''),
651-
width: dimensions.width / module.resolution,
652-
height: dimensions.height / module.resolution,
653-
deprecated: true,
654-
};
655-
656-
bundle.addAsset(img);
657-
658-
const code =
659-
'module.exports=' +
660-
JSON.stringify(filterObject(img, assetPropertyBlacklist))
661-
+ ';';
662-
663-
return new ModuleTransport({
664-
name: id,
665-
id: moduleId,
666-
code: code,
667-
sourceCode: code,
668-
sourcePath: module.path,
669-
virtual: true,
670-
});
671-
});
672-
}
673-
674633
_generateAssetObjAndCode(module, assetPlugins, platform: mixed = null) {
675634
const relPath = getPathRelativeToRoot(this._projectRoots, module.path);
676635
var assetUrlPath = joinPath('/assets', pathDirname(relPath));

packager/react-packager/src/ModuleGraph/node-haste/node-haste.flow.js

-14
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,6 @@ export type FastFS = {
5454
matches(directory: Path, pattern: RegExp): Array<Path>,
5555
};
5656

57-
type DeprecatedAssetMapOptions = {|
58-
assetExts: Extensions,
59-
files: Array<Path>,
60-
helpers: DependencyGraphHelpers,
61-
platforms: Platforms,
62-
|};
63-
64-
declare class DeprecatedAssetMap {
65-
// node-haste/DependencyGraph/DeprecatedAssetMap.js
66-
constructor(options: DeprecatedAssetMapOptions): void,
67-
}
68-
export type DeprecatedAssetMapT = DeprecatedAssetMap;
69-
7057
type HasteMapOptions = {|
7158
allowRelativePaths: boolean,
7259
extensions: Extensions,
@@ -89,7 +76,6 @@ type ResolutionRequestOptions = {|
8976
platforms: Platforms,
9077
preferNativePlatform: true,
9178
hasteMap: HasteMap,
92-
deprecatedAssetMap: DeprecatedAssetMap,
9379
helpers: DependencyGraphHelpers,
9480
moduleCache: ModuleCache,
9581
fastfs: FastFS,

packager/react-packager/src/ModuleGraph/node-haste/node-haste.js

-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
'use strict';
1313

1414
import type { // eslint-disable-line sort-requires
15-
DeprecatedAssetMapT,
1615
Extensions,
1716
HasteMapT,
1817
Path,
@@ -25,7 +24,6 @@ import type {
2524
} from '../types.flow';
2625

2726
const DependencyGraphHelpers = require('../../node-haste/DependencyGraph/DependencyGraphHelpers');
28-
const DeprecatedAssetMap: Class<DeprecatedAssetMapT> = require('../../node-haste/DependencyGraph/DeprecatedAssetMap');
2927
const FastFS = require('./FastFS');
3028
const HasteMap: Class<HasteMapT> = require('../../node-haste/DependencyGraph/HasteMap');
3129
const Module = require('./Module');
@@ -58,12 +56,6 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
5856
assetExts,
5957
providesModuleNodeModules: defaults.providesModuleNodeModules,
6058
});
61-
const deprecatedAssetMap = new DeprecatedAssetMap({
62-
assetExts,
63-
files,
64-
helpers,
65-
platforms,
66-
});
6759

6860
const fastfs = new FastFS(files);
6961
const moduleCache = new ModuleCache(fastfs, getTransformedFile);
@@ -83,7 +75,6 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
8375
let resolutionRequest = resolutionRequests[platform];
8476
if (!resolutionRequest) {
8577
resolutionRequest = resolutionRequests[platform] = new ResolutionRequest({
86-
deprecatedAssetMap,
8778
extraNodeModules,
8879
fastfs,
8980
hasteMap,

packager/react-packager/src/Resolver/index.js

-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ const validateOpts = declareOpts({
3131
type: 'string',
3232
default: 'haste',
3333
},
34-
assetRoots: {
35-
type: 'array',
36-
default: [],
37-
},
3834
watch: {
3935
type: 'boolean',
4036
default: false,
@@ -92,7 +88,6 @@ class Resolver {
9288

9389
this._depGraph = new DependencyGraph({
9490
roots: opts.projectRoots,
95-
assetRoots_DEPRECATED: opts.assetRoots,
9691
assetExts: opts.assetExts,
9792
ignoreFilePath: function(filepath) {
9893
return filepath.indexOf('__tests__') !== -1 ||

0 commit comments

Comments
 (0)