mirror of
https://github.com/status-im/metro.git
synced 2025-02-10 10:07:12 +00:00
Do not include assets source code in the sourcemaps
Summary: As reported in https://github.com/facebook/metro/issues/109, the sourcemaps generated by metro are including the binary data of all the assets, which adds a lot of overhead and is not useful at all. This commit removes the assets contents from the sourcemaps to fix https://github.com/facebook/metro/issues/109 Reviewed By: jeanlauliac Differential Revision: D6649741 fbshipit-source-id: 8b09d429a1aa8d487557c22440bfa73ae55d03bd
This commit is contained in:
parent
dd16d7427a
commit
8640847e47
@ -14,6 +14,9 @@
|
||||
|
||||
const Module = require('./Module');
|
||||
|
||||
import type {TransformedCode} from '../JSTransformer/worker';
|
||||
import type {ReadResult} from './Module';
|
||||
|
||||
class AssetModule extends Module {
|
||||
getPackage() {
|
||||
return null;
|
||||
@ -26,6 +29,14 @@ class AssetModule extends Module {
|
||||
isAsset() {
|
||||
return true;
|
||||
}
|
||||
|
||||
_finalizeReadResult(source: string, result: TransformedCode): ReadResult {
|
||||
// We do not want to return the "source code" of assets, since it's going to
|
||||
// be binary data and can potentially be very large. This source property
|
||||
// is only used to generate the sourcemaps (since we include all the
|
||||
// modules original sources in the sourcemaps).
|
||||
return {...result, source: ''};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AssetModule;
|
||||
|
@ -12,12 +12,44 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs').mock('../../lib/TransformCaching');
|
||||
|
||||
const AssetModule = require('../AssetModule');
|
||||
const DependencyGraphHelpers = require('../DependencyGraph/DependencyGraphHelpers');
|
||||
const ModuleCache = require('../ModuleCache');
|
||||
const TransformCaching = require('../../lib/TransformCaching');
|
||||
const fs = require('fs');
|
||||
|
||||
describe('AssetModule:', () => {
|
||||
const defaults = {file: '/arbitrary.png'};
|
||||
|
||||
beforeEach(() => {
|
||||
fs.__setMockFilesystem({root: {'image.png': 'png data'}});
|
||||
});
|
||||
|
||||
it('is an asset', () => {
|
||||
expect(new AssetModule(defaults).isAsset()).toBe(true);
|
||||
});
|
||||
|
||||
it('returns an empty source code for an asset', async () => {
|
||||
const module = new AssetModule({
|
||||
depGraphHelpers: new DependencyGraphHelpers({
|
||||
providesModuleNodeModules: [],
|
||||
assetExts: ['png'],
|
||||
}),
|
||||
file: '/root/image.png',
|
||||
getTransformCacheKey: () => 'foo',
|
||||
localPath: 'image.png',
|
||||
moduleCache: new ModuleCache({}),
|
||||
options: {transformCache: TransformCaching.mocked()},
|
||||
transformCode: () => {
|
||||
return Promise.resolve({code: 'module.exports = "asset";'});
|
||||
},
|
||||
});
|
||||
|
||||
const data = await module.read();
|
||||
|
||||
expect(data.code).toBe('module.exports = "asset";');
|
||||
expect(data.source).toBe('');
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user