mirror of https://github.com/status-im/metro.git
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
This commit is contained in:
parent
1b8582a2d1
commit
a810087624
|
@ -117,7 +117,7 @@ Builds a bundle according to the provided options.
|
||||||
#### `bundleOptions`
|
#### `bundleOptions`
|
||||||
|
|
||||||
* `entryFile` string (required): the entry file of the bundle, relative to one
|
* `entryFile` string (required): the entry file of the bundle, relative to one
|
||||||
of the asset roots.
|
of the roots.
|
||||||
* `dev` boolean (defaults to `true`): sets a global `__DEV__` variable
|
* `dev` boolean (defaults to `true`): sets a global `__DEV__` variable
|
||||||
which will effect how the React Native core libraries behave.
|
which will effect how the React Native core libraries behave.
|
||||||
* `minify` boolean: Whether to minify code and apply production optimizations.
|
* `minify` boolean: Whether to minify code and apply production optimizations.
|
||||||
|
|
|
@ -38,7 +38,6 @@ describe('Bundler', function() {
|
||||||
id,
|
id,
|
||||||
dependencies,
|
dependencies,
|
||||||
isAsset,
|
isAsset,
|
||||||
isAsset_DEPRECATED,
|
|
||||||
isJSON,
|
isJSON,
|
||||||
isPolyfill,
|
isPolyfill,
|
||||||
resolution,
|
resolution,
|
||||||
|
@ -50,7 +49,6 @@ describe('Bundler', function() {
|
||||||
getName: () => Promise.resolve(id),
|
getName: () => Promise.resolve(id),
|
||||||
isJSON: () => isJSON,
|
isJSON: () => isJSON,
|
||||||
isAsset: () => isAsset,
|
isAsset: () => isAsset,
|
||||||
isAsset_DEPRECATED: () => isAsset_DEPRECATED,
|
|
||||||
isPolyfill: () => isPolyfill,
|
isPolyfill: () => isPolyfill,
|
||||||
read: () => ({
|
read: () => ({
|
||||||
code: 'arbitrary',
|
code: 'arbitrary',
|
||||||
|
@ -100,13 +98,6 @@ describe('Bundler', function() {
|
||||||
modules = [
|
modules = [
|
||||||
createModule({id: 'foo', path: '/root/foo.js', dependencies: []}),
|
createModule({id: 'foo', path: '/root/foo.js', dependencies: []}),
|
||||||
createModule({id: 'bar', path: '/root/bar.js', dependencies: []}),
|
createModule({id: 'bar', path: '/root/bar.js', dependencies: []}),
|
||||||
createModule({
|
|
||||||
path: '/root/img/img.png',
|
|
||||||
id: 'image!img',
|
|
||||||
isAsset_DEPRECATED: true,
|
|
||||||
dependencies: [],
|
|
||||||
resolution: 2,
|
|
||||||
}),
|
|
||||||
createModule({
|
createModule({
|
||||||
id: 'new_image.png',
|
id: 'new_image.png',
|
||||||
path: '/root/img/new_image.png',
|
path: '/root/img/new_image.png',
|
||||||
|
@ -166,9 +157,8 @@ describe('Bundler', function() {
|
||||||
|
|
||||||
expect(ithAddedModule(0)).toEqual('/root/foo.js');
|
expect(ithAddedModule(0)).toEqual('/root/foo.js');
|
||||||
expect(ithAddedModule(1)).toEqual('/root/bar.js');
|
expect(ithAddedModule(1)).toEqual('/root/bar.js');
|
||||||
expect(ithAddedModule(2)).toEqual('/root/img/img.png');
|
expect(ithAddedModule(2)).toEqual('/root/img/new_image.png');
|
||||||
expect(ithAddedModule(3)).toEqual('/root/img/new_image.png');
|
expect(ithAddedModule(3)).toEqual('/root/file.json');
|
||||||
expect(ithAddedModule(4)).toEqual('/root/file.json');
|
|
||||||
|
|
||||||
expect(bundle.finalize.mock.calls[0]).toEqual([{
|
expect(bundle.finalize.mock.calls[0]).toEqual([{
|
||||||
runMainModule: true,
|
runMainModule: true,
|
||||||
|
@ -177,15 +167,6 @@ describe('Bundler', function() {
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
expect(bundle.addAsset.mock.calls[0]).toEqual([{
|
expect(bundle.addAsset.mock.calls[0]).toEqual([{
|
||||||
__packager_asset: true,
|
|
||||||
path: '/root/img/img.png',
|
|
||||||
uri: 'img',
|
|
||||||
width: 25,
|
|
||||||
height: 50,
|
|
||||||
deprecated: true,
|
|
||||||
}]);
|
|
||||||
|
|
||||||
expect(bundle.addAsset.mock.calls[1]).toEqual([{
|
|
||||||
__packager_asset: true,
|
__packager_asset: true,
|
||||||
fileSystemLocation: '/root/img',
|
fileSystemLocation: '/root/img',
|
||||||
httpServerLocation: '/assets/img',
|
httpServerLocation: '/assets/img',
|
||||||
|
@ -245,7 +226,7 @@ describe('Bundler', function() {
|
||||||
sourceMapUrl: 'source_map_url',
|
sourceMapUrl: 'source_map_url',
|
||||||
assetPlugins: ['mockPlugin1', 'asyncMockPlugin2'],
|
assetPlugins: ['mockPlugin1', 'asyncMockPlugin2'],
|
||||||
}).then(bundle => {
|
}).then(bundle => {
|
||||||
expect(bundle.addAsset.mock.calls[1]).toEqual([{
|
expect(bundle.addAsset.mock.calls[0]).toEqual([{
|
||||||
__packager_asset: true,
|
__packager_asset: true,
|
||||||
fileSystemLocation: '/root/img',
|
fileSystemLocation: '/root/img',
|
||||||
httpServerLocation: '/assets/img',
|
httpServerLocation: '/assets/img',
|
||||||
|
@ -334,7 +315,6 @@ describe('Bundler', function() {
|
||||||
.then((paths) => expect(paths).toEqual([
|
.then((paths) => expect(paths).toEqual([
|
||||||
'/root/foo.js',
|
'/root/foo.js',
|
||||||
'/root/bar.js',
|
'/root/bar.js',
|
||||||
'/root/img/img.png',
|
|
||||||
'/root/img/new_image.png',
|
'/root/img/new_image.png',
|
||||||
'/root/img/new_image@2x.png',
|
'/root/img/new_image@2x.png',
|
||||||
'/root/img/new_image@3x.png',
|
'/root/img/new_image@3x.png',
|
||||||
|
|
|
@ -79,10 +79,6 @@ const validateOpts = declareOpts({
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
assetRoots: {
|
|
||||||
type: 'array',
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
assetExts: {
|
assetExts: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
default: ['png'],
|
default: ['png'],
|
||||||
|
@ -120,7 +116,6 @@ type Options = {
|
||||||
resetCache: boolean,
|
resetCache: boolean,
|
||||||
transformModulePath: string,
|
transformModulePath: string,
|
||||||
extraNodeModules: {},
|
extraNodeModules: {},
|
||||||
assetRoots: Array<string>,
|
|
||||||
assetExts: Array<string>,
|
assetExts: Array<string>,
|
||||||
watch: boolean,
|
watch: boolean,
|
||||||
assetServer: AssetServer,
|
assetServer: AssetServer,
|
||||||
|
@ -182,7 +177,6 @@ class Bundler {
|
||||||
|
|
||||||
this._resolver = new Resolver({
|
this._resolver = new Resolver({
|
||||||
assetExts: opts.assetExts,
|
assetExts: opts.assetExts,
|
||||||
assetRoots: opts.assetRoots,
|
|
||||||
blacklistRE: opts.blacklistRE,
|
blacklistRE: opts.blacklistRE,
|
||||||
cache: this._cache,
|
cache: this._cache,
|
||||||
extraNodeModules: opts.extraNodeModules,
|
extraNodeModules: opts.extraNodeModules,
|
||||||
|
@ -603,10 +597,7 @@ class Bundler {
|
||||||
let moduleTransport;
|
let moduleTransport;
|
||||||
const moduleId = getModuleId(module);
|
const moduleId = getModuleId(module);
|
||||||
|
|
||||||
if (module.isAsset_DEPRECATED()) {
|
if (module.isAsset()) {
|
||||||
moduleTransport =
|
|
||||||
this._generateAssetModule_DEPRECATED(bundle, module, moduleId);
|
|
||||||
} else if (module.isAsset()) {
|
|
||||||
moduleTransport = this._generateAssetModule(
|
moduleTransport = this._generateAssetModule(
|
||||||
bundle, module, moduleId, assetPlugins, transformOptions.platform);
|
bundle, module, moduleId, assetPlugins, transformOptions.platform);
|
||||||
}
|
}
|
||||||
|
@ -639,38 +630,6 @@ class Bundler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateAssetModule_DEPRECATED(bundle, module, moduleId) {
|
|
||||||
return Promise.all([
|
|
||||||
sizeOf(module.path),
|
|
||||||
module.getName(),
|
|
||||||
]).then(([dimensions, id]) => {
|
|
||||||
const img = {
|
|
||||||
__packager_asset: true,
|
|
||||||
path: module.path,
|
|
||||||
uri: id.replace(/^[^!]+!/, ''),
|
|
||||||
width: dimensions.width / module.resolution,
|
|
||||||
height: dimensions.height / module.resolution,
|
|
||||||
deprecated: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
bundle.addAsset(img);
|
|
||||||
|
|
||||||
const code =
|
|
||||||
'module.exports=' +
|
|
||||||
JSON.stringify(filterObject(img, assetPropertyBlacklist))
|
|
||||||
+ ';';
|
|
||||||
|
|
||||||
return new ModuleTransport({
|
|
||||||
name: id,
|
|
||||||
id: moduleId,
|
|
||||||
code: code,
|
|
||||||
sourceCode: code,
|
|
||||||
sourcePath: module.path,
|
|
||||||
virtual: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_generateAssetObjAndCode(module, assetPlugins, platform: mixed = null) {
|
_generateAssetObjAndCode(module, assetPlugins, platform: mixed = null) {
|
||||||
const relPath = getPathRelativeToRoot(this._projectRoots, module.path);
|
const relPath = getPathRelativeToRoot(this._projectRoots, module.path);
|
||||||
var assetUrlPath = joinPath('/assets', pathDirname(relPath));
|
var assetUrlPath = joinPath('/assets', pathDirname(relPath));
|
||||||
|
|
|
@ -54,19 +54,6 @@ export type FastFS = {
|
||||||
matches(directory: Path, pattern: RegExp): Array<Path>,
|
matches(directory: Path, pattern: RegExp): Array<Path>,
|
||||||
};
|
};
|
||||||
|
|
||||||
type DeprecatedAssetMapOptions = {|
|
|
||||||
assetExts: Extensions,
|
|
||||||
files: Array<Path>,
|
|
||||||
helpers: DependencyGraphHelpers,
|
|
||||||
platforms: Platforms,
|
|
||||||
|};
|
|
||||||
|
|
||||||
declare class DeprecatedAssetMap {
|
|
||||||
// node-haste/DependencyGraph/DeprecatedAssetMap.js
|
|
||||||
constructor(options: DeprecatedAssetMapOptions): void,
|
|
||||||
}
|
|
||||||
export type DeprecatedAssetMapT = DeprecatedAssetMap;
|
|
||||||
|
|
||||||
type HasteMapOptions = {|
|
type HasteMapOptions = {|
|
||||||
allowRelativePaths: boolean,
|
allowRelativePaths: boolean,
|
||||||
extensions: Extensions,
|
extensions: Extensions,
|
||||||
|
@ -89,7 +76,6 @@ type ResolutionRequestOptions = {|
|
||||||
platforms: Platforms,
|
platforms: Platforms,
|
||||||
preferNativePlatform: true,
|
preferNativePlatform: true,
|
||||||
hasteMap: HasteMap,
|
hasteMap: HasteMap,
|
||||||
deprecatedAssetMap: DeprecatedAssetMap,
|
|
||||||
helpers: DependencyGraphHelpers,
|
helpers: DependencyGraphHelpers,
|
||||||
moduleCache: ModuleCache,
|
moduleCache: ModuleCache,
|
||||||
fastfs: FastFS,
|
fastfs: FastFS,
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import type { // eslint-disable-line sort-requires
|
import type { // eslint-disable-line sort-requires
|
||||||
DeprecatedAssetMapT,
|
|
||||||
Extensions,
|
Extensions,
|
||||||
HasteMapT,
|
HasteMapT,
|
||||||
Path,
|
Path,
|
||||||
|
@ -25,7 +24,6 @@ import type {
|
||||||
} from '../types.flow';
|
} from '../types.flow';
|
||||||
|
|
||||||
const DependencyGraphHelpers = require('../../node-haste/DependencyGraph/DependencyGraphHelpers');
|
const DependencyGraphHelpers = require('../../node-haste/DependencyGraph/DependencyGraphHelpers');
|
||||||
const DeprecatedAssetMap: Class<DeprecatedAssetMapT> = require('../../node-haste/DependencyGraph/DeprecatedAssetMap');
|
|
||||||
const FastFS = require('./FastFS');
|
const FastFS = require('./FastFS');
|
||||||
const HasteMap: Class<HasteMapT> = require('../../node-haste/DependencyGraph/HasteMap');
|
const HasteMap: Class<HasteMapT> = require('../../node-haste/DependencyGraph/HasteMap');
|
||||||
const Module = require('./Module');
|
const Module = require('./Module');
|
||||||
|
@ -58,12 +56,6 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
|
||||||
assetExts,
|
assetExts,
|
||||||
providesModuleNodeModules: defaults.providesModuleNodeModules,
|
providesModuleNodeModules: defaults.providesModuleNodeModules,
|
||||||
});
|
});
|
||||||
const deprecatedAssetMap = new DeprecatedAssetMap({
|
|
||||||
assetExts,
|
|
||||||
files,
|
|
||||||
helpers,
|
|
||||||
platforms,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fastfs = new FastFS(files);
|
const fastfs = new FastFS(files);
|
||||||
const moduleCache = new ModuleCache(fastfs, getTransformedFile);
|
const moduleCache = new ModuleCache(fastfs, getTransformedFile);
|
||||||
|
@ -83,7 +75,6 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
|
||||||
let resolutionRequest = resolutionRequests[platform];
|
let resolutionRequest = resolutionRequests[platform];
|
||||||
if (!resolutionRequest) {
|
if (!resolutionRequest) {
|
||||||
resolutionRequest = resolutionRequests[platform] = new ResolutionRequest({
|
resolutionRequest = resolutionRequests[platform] = new ResolutionRequest({
|
||||||
deprecatedAssetMap,
|
|
||||||
extraNodeModules,
|
extraNodeModules,
|
||||||
fastfs,
|
fastfs,
|
||||||
hasteMap,
|
hasteMap,
|
||||||
|
|
|
@ -31,10 +31,6 @@ const validateOpts = declareOpts({
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'haste',
|
default: 'haste',
|
||||||
},
|
},
|
||||||
assetRoots: {
|
|
||||||
type: 'array',
|
|
||||||
default: [],
|
|
||||||
},
|
|
||||||
watch: {
|
watch: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
|
@ -92,7 +88,6 @@ class Resolver {
|
||||||
|
|
||||||
this._depGraph = new DependencyGraph({
|
this._depGraph = new DependencyGraph({
|
||||||
roots: opts.projectRoots,
|
roots: opts.projectRoots,
|
||||||
assetRoots_DEPRECATED: opts.assetRoots,
|
|
||||||
assetExts: opts.assetExts,
|
assetExts: opts.assetExts,
|
||||||
ignoreFilePath: function(filepath) {
|
ignoreFilePath: function(filepath) {
|
||||||
return filepath.indexOf('__tests__') !== -1 ||
|
return filepath.indexOf('__tests__') !== -1 ||
|
||||||
|
|
|
@ -79,10 +79,6 @@ const validateOpts = declareOpts({
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
assetRoots: {
|
|
||||||
type: 'array',
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
assetExts: {
|
assetExts: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
default: defaults.assetExts,
|
default: defaults.assetExts,
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const Module = require('./Module');
|
|
||||||
const getAssetDataFromName = require('./lib/getAssetDataFromName');
|
|
||||||
|
|
||||||
class AssetModule_DEPRECATED extends Module {
|
|
||||||
constructor(args, platforms) {
|
|
||||||
super(args);
|
|
||||||
const {resolution, name} = getAssetDataFromName(this.path, platforms);
|
|
||||||
this.resolution = resolution;
|
|
||||||
this.name = name;
|
|
||||||
this.platforms = platforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
isHaste() {
|
|
||||||
return Promise.resolve(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return Promise.resolve(`image!${this.name}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
getDependencies() {
|
|
||||||
return Promise.resolve([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
hash() {
|
|
||||||
return `AssetModule_DEPRECATED : ${this.path}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
isJSON() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
isAsset_DEPRECATED() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolution() {
|
|
||||||
return getAssetDataFromName(this.path, this.platforms).resolution;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = AssetModule_DEPRECATED;
|
|
|
@ -1,73 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const AssetModule_DEPRECATED = require('../AssetModule_DEPRECATED');
|
|
||||||
const debug = require('debug')('ReactNativePackager:DependencyGraph');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
class DeprecatedAssetMap {
|
|
||||||
constructor({
|
|
||||||
assetExts,
|
|
||||||
helpers,
|
|
||||||
platforms,
|
|
||||||
files,
|
|
||||||
}) {
|
|
||||||
this._helpers = helpers;
|
|
||||||
this._map = Object.create(null);
|
|
||||||
this._assetExts = assetExts;
|
|
||||||
this._platforms = platforms;
|
|
||||||
|
|
||||||
files.forEach(file => this._processAsset(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(fromModule, toModuleName) {
|
|
||||||
if (this._disabled) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const assetMatch = toModuleName.match(/^image!(.+)/);
|
|
||||||
if (assetMatch && assetMatch[1]) {
|
|
||||||
if (!this._map[assetMatch[1]]) {
|
|
||||||
debug('WARINING: Cannot find asset:', assetMatch[1]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this._map[assetMatch[1]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_processAsset(file) {
|
|
||||||
const ext = this._helpers.extname(file);
|
|
||||||
if (this._assetExts.indexOf(ext) !== -1) {
|
|
||||||
const name = assetName(file, ext);
|
|
||||||
if (this._map[name] != null) {
|
|
||||||
debug('Conflicting assets', name);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._map[name] = new AssetModule_DEPRECATED({ file }, this._platforms);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processFileChange(type, filePath, fstat) {
|
|
||||||
const name = assetName(filePath);
|
|
||||||
if (type === 'change' || type === 'delete') {
|
|
||||||
delete this._map[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'change' || type === 'add') {
|
|
||||||
this._processAsset(filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function assetName(file, ext) {
|
|
||||||
return path.basename(file, '.' + ext).replace(/@[\d\.]+x/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = DeprecatedAssetMap;
|
|
|
@ -26,7 +26,6 @@ class ResolutionRequest {
|
||||||
preferNativePlatform,
|
preferNativePlatform,
|
||||||
entryPath,
|
entryPath,
|
||||||
hasteMap,
|
hasteMap,
|
||||||
deprecatedAssetMap,
|
|
||||||
helpers,
|
helpers,
|
||||||
moduleCache,
|
moduleCache,
|
||||||
fastfs,
|
fastfs,
|
||||||
|
@ -38,7 +37,6 @@ class ResolutionRequest {
|
||||||
this._preferNativePlatform = preferNativePlatform;
|
this._preferNativePlatform = preferNativePlatform;
|
||||||
this._entryPath = entryPath;
|
this._entryPath = entryPath;
|
||||||
this._hasteMap = hasteMap;
|
this._hasteMap = hasteMap;
|
||||||
this._deprecatedAssetMap = deprecatedAssetMap;
|
|
||||||
this._helpers = helpers;
|
this._helpers = helpers;
|
||||||
this._moduleCache = moduleCache;
|
this._moduleCache = moduleCache;
|
||||||
this._fastfs = fastfs;
|
this._fastfs = fastfs;
|
||||||
|
@ -63,14 +61,6 @@ class ResolutionRequest {
|
||||||
return Promise.resolve(this._immediateResolutionCache[resHash]);
|
return Promise.resolve(this._immediateResolutionCache[resHash]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const asset_DEPRECATED = this._deprecatedAssetMap.resolve(
|
|
||||||
fromModule,
|
|
||||||
toModuleName
|
|
||||||
);
|
|
||||||
if (asset_DEPRECATED) {
|
|
||||||
return Promise.resolve(asset_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
const cacheResult = (result) => {
|
const cacheResult = (result) => {
|
||||||
this._immediateResolutionCache[resHash] = result;
|
this._immediateResolutionCache[resHash] = result;
|
||||||
return result;
|
return result;
|
||||||
|
@ -206,8 +196,8 @@ class ResolutionRequest {
|
||||||
function collect(module) {
|
function collect(module) {
|
||||||
collectionsInProgress.start(module);
|
collectionsInProgress.start(module);
|
||||||
const result = resolveDependencies(module)
|
const result = resolveDependencies(module)
|
||||||
.then(result => addMockDependencies(module, result))
|
.then(deps => addMockDependencies(module, deps))
|
||||||
.then(result => crawlDependencies(module, result));
|
.then(deps => crawlDependencies(module, deps));
|
||||||
const end = () => collectionsInProgress.end(module);
|
const end = () => collectionsInProgress.end(module);
|
||||||
result.then(end, end);
|
result.then(end, end);
|
||||||
return result;
|
return result;
|
||||||
|
@ -252,9 +242,9 @@ class ResolutionRequest {
|
||||||
let mocks = null;
|
let mocks = null;
|
||||||
if (pattern) {
|
if (pattern) {
|
||||||
mocks = Object.create(null);
|
mocks = Object.create(null);
|
||||||
this._fastfs.matchFilesByPattern(pattern).forEach(file =>
|
this._fastfs.matchFilesByPattern(pattern).forEach(file => {
|
||||||
mocks[path.basename(file, path.extname(file))] = file
|
mocks[path.basename(file, path.extname(file))] = file;
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
return Promise.resolve(mocks);
|
return Promise.resolve(mocks);
|
||||||
}
|
}
|
||||||
|
@ -532,8 +522,8 @@ function resolveKeyWithPromise([key, promise]) {
|
||||||
return promise.then(value => [key, value]);
|
return promise.then(value => [key, value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRelativeImport(path) {
|
function isRelativeImport(filePath) {
|
||||||
return /^[.][.]?(?:[/]|$)/.test(path);
|
return /^[.][.]?(?:[/]|$)/.test(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ResolutionRequest;
|
module.exports = ResolutionRequest;
|
||||||
|
|
|
@ -219,8 +219,6 @@ class Module {
|
||||||
callback: (error: ?Error, result: ?TransformedCode) => void,
|
callback: (error: ?Error, result: ?TransformedCode) => void,
|
||||||
) {
|
) {
|
||||||
const {_transformCode, _transformCacheKey} = this;
|
const {_transformCode, _transformCacheKey} = this;
|
||||||
// AssetModule_DEPRECATED doesn't provide transformCode, but these should
|
|
||||||
// never be transformed anyway.
|
|
||||||
invariant(_transformCode != null, 'missing code transform funtion');
|
invariant(_transformCode != null, 'missing code transform funtion');
|
||||||
invariant(_transformCacheKey != null, 'missing cache key');
|
invariant(_transformCacheKey != null, 'missing cache key');
|
||||||
this._readSourceCode()
|
this._readSourceCode()
|
||||||
|
@ -311,16 +309,11 @@ class Module {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isAsset_DEPRECATED() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
hash: this.hash(),
|
hash: this.hash(),
|
||||||
isJSON: this.isJSON(),
|
isJSON: this.isJSON(),
|
||||||
isAsset: this.isAsset(),
|
isAsset: this.isAsset(),
|
||||||
isAsset_DEPRECATED: this.isAsset_DEPRECATED(),
|
|
||||||
type: this.type,
|
type: this.type,
|
||||||
path: this.path,
|
path: this.path,
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
const Cache = require('./Cache');
|
const Cache = require('./Cache');
|
||||||
const DependencyGraphHelpers = require('./DependencyGraph/DependencyGraphHelpers');
|
const DependencyGraphHelpers = require('./DependencyGraph/DependencyGraphHelpers');
|
||||||
const DeprecatedAssetMap = require('./DependencyGraph/DeprecatedAssetMap');
|
|
||||||
const Fastfs = require('./fastfs');
|
const Fastfs = require('./fastfs');
|
||||||
const HasteMap = require('./DependencyGraph/HasteMap');
|
const HasteMap = require('./DependencyGraph/HasteMap');
|
||||||
const JestHasteMap = require('jest-haste-map');
|
const JestHasteMap = require('jest-haste-map');
|
||||||
|
@ -46,18 +45,13 @@ const {
|
||||||
print,
|
print,
|
||||||
} = require('../Logger');
|
} = require('../Logger');
|
||||||
|
|
||||||
const escapePath = (p: string) => {
|
|
||||||
return (path.sep === '\\') ? p.replace(/(\/|\\(?!\.))/g, '\\\\') : p;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DependencyGraph {
|
class DependencyGraph {
|
||||||
|
|
||||||
_opts: {
|
_opts: {|
|
||||||
roots: Array<string>,
|
roots: Array<string>,
|
||||||
ignoreFilePath: (filePath: string) => boolean,
|
ignoreFilePath: (filePath: string) => boolean,
|
||||||
watch: boolean,
|
watch: boolean,
|
||||||
forceNodeFilesystemAPI: boolean,
|
forceNodeFilesystemAPI: boolean,
|
||||||
assetRoots_DEPRECATED: Array<string>,
|
|
||||||
assetExts: Array<string>,
|
assetExts: Array<string>,
|
||||||
providesModuleNodeModules: Array<string>,
|
providesModuleNodeModules: Array<string>,
|
||||||
platforms: Set<mixed>,
|
platforms: Set<mixed>,
|
||||||
|
@ -67,17 +61,14 @@ class DependencyGraph {
|
||||||
transformCode: TransformCode,
|
transformCode: TransformCode,
|
||||||
transformCacheKey: string,
|
transformCacheKey: string,
|
||||||
shouldThrowOnUnresolvedErrors: () => boolean,
|
shouldThrowOnUnresolvedErrors: () => boolean,
|
||||||
enableAssetMap: boolean,
|
|
||||||
moduleOptions: ModuleOptions,
|
moduleOptions: ModuleOptions,
|
||||||
extraNodeModules: mixed,
|
extraNodeModules: mixed,
|
||||||
useWatchman: boolean,
|
useWatchman: boolean,
|
||||||
maxWorkers: number,
|
maxWorkers: number,
|
||||||
resetCache: boolean,
|
resetCache: boolean,
|
||||||
};
|
|};
|
||||||
_assetDependencies: mixed;
|
_assetDependencies: mixed;
|
||||||
_assetPattern: RegExp;
|
|
||||||
_cache: Cache;
|
_cache: Cache;
|
||||||
_deprecatedAssetMap: DeprecatedAssetMap;
|
|
||||||
_fastfs: Fastfs;
|
_fastfs: Fastfs;
|
||||||
_haste: JestHasteMap;
|
_haste: JestHasteMap;
|
||||||
_hasteMap: HasteMap;
|
_hasteMap: HasteMap;
|
||||||
|
@ -92,7 +83,6 @@ class DependencyGraph {
|
||||||
ignoreFilePath,
|
ignoreFilePath,
|
||||||
watch,
|
watch,
|
||||||
forceNodeFilesystemAPI,
|
forceNodeFilesystemAPI,
|
||||||
assetRoots_DEPRECATED,
|
|
||||||
assetExts,
|
assetExts,
|
||||||
providesModuleNodeModules,
|
providesModuleNodeModules,
|
||||||
platforms,
|
platforms,
|
||||||
|
@ -103,7 +93,6 @@ class DependencyGraph {
|
||||||
transformCode,
|
transformCode,
|
||||||
transformCacheKey,
|
transformCacheKey,
|
||||||
shouldThrowOnUnresolvedErrors = () => true,
|
shouldThrowOnUnresolvedErrors = () => true,
|
||||||
enableAssetMap,
|
|
||||||
assetDependencies,
|
assetDependencies,
|
||||||
moduleOptions,
|
moduleOptions,
|
||||||
extraNodeModules,
|
extraNodeModules,
|
||||||
|
@ -116,7 +105,6 @@ class DependencyGraph {
|
||||||
ignoreFilePath: (filePath: string) => boolean,
|
ignoreFilePath: (filePath: string) => boolean,
|
||||||
watch: boolean,
|
watch: boolean,
|
||||||
forceNodeFilesystemAPI?: boolean,
|
forceNodeFilesystemAPI?: boolean,
|
||||||
assetRoots_DEPRECATED: Array<string>,
|
|
||||||
assetExts: Array<string>,
|
assetExts: Array<string>,
|
||||||
providesModuleNodeModules: Array<string>,
|
providesModuleNodeModules: Array<string>,
|
||||||
platforms: mixed,
|
platforms: mixed,
|
||||||
|
@ -127,7 +115,6 @@ class DependencyGraph {
|
||||||
transformCode: TransformCode,
|
transformCode: TransformCode,
|
||||||
transformCacheKey: string,
|
transformCacheKey: string,
|
||||||
shouldThrowOnUnresolvedErrors: () => boolean,
|
shouldThrowOnUnresolvedErrors: () => boolean,
|
||||||
enableAssetMap: boolean,
|
|
||||||
assetDependencies: mixed,
|
assetDependencies: mixed,
|
||||||
moduleOptions: ?ModuleOptions,
|
moduleOptions: ?ModuleOptions,
|
||||||
extraNodeModules: mixed,
|
extraNodeModules: mixed,
|
||||||
|
@ -140,7 +127,6 @@ class DependencyGraph {
|
||||||
ignoreFilePath: ignoreFilePath || (() => {}),
|
ignoreFilePath: ignoreFilePath || (() => {}),
|
||||||
watch: !!watch,
|
watch: !!watch,
|
||||||
forceNodeFilesystemAPI: !!forceNodeFilesystemAPI,
|
forceNodeFilesystemAPI: !!forceNodeFilesystemAPI,
|
||||||
assetRoots_DEPRECATED: assetRoots_DEPRECATED || [],
|
|
||||||
assetExts: assetExts || [],
|
assetExts: assetExts || [],
|
||||||
providesModuleNodeModules,
|
providesModuleNodeModules,
|
||||||
platforms: new Set(platforms || []),
|
platforms: new Set(platforms || []),
|
||||||
|
@ -150,7 +136,6 @@ class DependencyGraph {
|
||||||
transformCode,
|
transformCode,
|
||||||
transformCacheKey,
|
transformCacheKey,
|
||||||
shouldThrowOnUnresolvedErrors,
|
shouldThrowOnUnresolvedErrors,
|
||||||
enableAssetMap: enableAssetMap || true,
|
|
||||||
moduleOptions: moduleOptions || {
|
moduleOptions: moduleOptions || {
|
||||||
cacheTransformResults: true,
|
cacheTransformResults: true,
|
||||||
},
|
},
|
||||||
|
@ -160,8 +145,6 @@ class DependencyGraph {
|
||||||
maxWorkers,
|
maxWorkers,
|
||||||
resetCache,
|
resetCache,
|
||||||
};
|
};
|
||||||
this._assetPattern =
|
|
||||||
new RegExp('^' + this._opts.assetRoots_DEPRECATED.map(escapePath).join('|'));
|
|
||||||
|
|
||||||
this._cache = cache;
|
this._cache = cache;
|
||||||
this._assetDependencies = assetDependencies;
|
this._assetDependencies = assetDependencies;
|
||||||
|
@ -186,7 +169,7 @@ class DependencyGraph {
|
||||||
providesModuleNodeModules: this._opts.providesModuleNodeModules,
|
providesModuleNodeModules: this._opts.providesModuleNodeModules,
|
||||||
resetCache: this._opts.resetCache,
|
resetCache: this._opts.resetCache,
|
||||||
retainAllFiles: true,
|
retainAllFiles: true,
|
||||||
roots: this._opts.roots.concat(this._opts.assetRoots_DEPRECATED),
|
roots: this._opts.roots,
|
||||||
useWatchman: this._opts.useWatchman,
|
useWatchman: this._opts.useWatchman,
|
||||||
watch: this._opts.watch,
|
watch: this._opts.watch,
|
||||||
});
|
});
|
||||||
|
@ -225,15 +208,6 @@ class DependencyGraph {
|
||||||
platforms: this._opts.platforms,
|
platforms: this._opts.platforms,
|
||||||
});
|
});
|
||||||
|
|
||||||
const assetFiles = hasteMap.hasteFS.matchFiles(this._assetPattern);
|
|
||||||
|
|
||||||
this._deprecatedAssetMap = new DeprecatedAssetMap({
|
|
||||||
helpers: this._helpers,
|
|
||||||
assetExts: this._opts.assetExts,
|
|
||||||
platforms: this._opts.platforms,
|
|
||||||
files: assetFiles,
|
|
||||||
});
|
|
||||||
|
|
||||||
this._haste.on('change', ({eventsQueue}) =>
|
this._haste.on('change', ({eventsQueue}) =>
|
||||||
eventsQueue.forEach(({type, filePath, stat}) =>
|
eventsQueue.forEach(({type, filePath, stat}) =>
|
||||||
this.processFileChange(type, filePath, stat)
|
this.processFileChange(type, filePath, stat)
|
||||||
|
@ -314,7 +288,6 @@ class DependencyGraph {
|
||||||
platforms: this._opts.platforms,
|
platforms: this._opts.platforms,
|
||||||
preferNativePlatform: this._opts.preferNativePlatform,
|
preferNativePlatform: this._opts.preferNativePlatform,
|
||||||
entryPath: absPath,
|
entryPath: absPath,
|
||||||
deprecatedAssetMap: this._deprecatedAssetMap,
|
|
||||||
hasteMap: this._hasteMap,
|
hasteMap: this._hasteMap,
|
||||||
helpers: this._helpers,
|
helpers: this._helpers,
|
||||||
moduleCache: this._moduleCache,
|
moduleCache: this._moduleCache,
|
||||||
|
@ -371,9 +344,6 @@ class DependencyGraph {
|
||||||
processFileChange(type: string, filePath: string, stat: Object) {
|
processFileChange(type: string, filePath: string, stat: Object) {
|
||||||
this._fastfs.processFileChange(type, filePath, stat);
|
this._fastfs.processFileChange(type, filePath, stat);
|
||||||
this._moduleCache.processFileChange(type, filePath, stat);
|
this._moduleCache.processFileChange(type, filePath, stat);
|
||||||
if (this._assetPattern.test(filePath)) {
|
|
||||||
this._deprecatedAssetMap.processFileChange(type, filePath, stat);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This code reports failures but doesn't block recovery in the dev server
|
// This code reports failures but doesn't block recovery in the dev server
|
||||||
// mode. When the hasteMap is left in an incorrect state, we'll rebuild when
|
// mode. When the hasteMap is left in an incorrect state, we'll rebuild when
|
||||||
|
|
|
@ -18,10 +18,6 @@ module.exports = {
|
||||||
return this._getRoots();
|
return this._getRoots();
|
||||||
},
|
},
|
||||||
|
|
||||||
getAssetRoots() {
|
|
||||||
return this._getRoots();
|
|
||||||
},
|
|
||||||
|
|
||||||
getAssetExts() {
|
getAssetExts() {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue