Change the Graph data structure to support multiple transform output types

Reviewed By: davidaurelio

Differential Revision: D7877461

fbshipit-source-id: 02a7bf2273768fed567aa931ecb8e65b3dd74502
This commit is contained in:
Rafael Oleza 2018-05-11 15:05:05 -07:00 committed by Facebook Github Bot
parent f9a0767498
commit 5c8b86aed5
25 changed files with 345 additions and 227 deletions

View File

@ -17,7 +17,7 @@ Object {
"version": 3,
},
"name": "entry.js",
"source": undefined,
"source": "source of entry",
"sourcePath": "/root/entry.js",
"type": "js/module",
},
@ -33,7 +33,7 @@ Object {
"version": 3,
},
"name": "entry2.js",
"source": undefined,
"source": "source of entry2",
"sourcePath": "/root/entry2.js",
"type": "js/module",
},
@ -49,7 +49,7 @@ Object {
"version": 3,
},
"name": "foo2.js",
"source": undefined,
"source": "source of foo2",
"sourcePath": "/root/foo2.js",
"type": "js/module",
},
@ -65,7 +65,7 @@ Object {
"version": 3,
},
"name": "foo.js",
"source": undefined,
"source": "source of foo",
"sourcePath": "/root/foo.js",
"type": "js/module",
},
@ -81,7 +81,7 @@ Object {
"version": 3,
},
"name": "baz.js",
"source": undefined,
"source": "source of baz",
"sourcePath": "/root/baz.js",
"type": "js/module/asset",
},
@ -97,7 +97,7 @@ Object {
"version": 3,
},
"name": "bar.js",
"source": undefined,
"source": "source of bar",
"sourcePath": "/root/bar.js",
"type": "js/module",
},
@ -113,7 +113,7 @@ Object {
"version": 3,
},
"name": "qux.js",
"source": undefined,
"source": "source of qux",
"sourcePath": "/root/qux.js",
"type": "js/module",
},
@ -131,7 +131,7 @@ Object {
"version": 3,
},
"name": "pre.js",
"source": undefined,
"source": "source of pre",
"sourcePath": "/root/pre.js",
"type": "js/script",
},

View File

@ -13,7 +13,7 @@
const createModuleIdFactory = require('../../../lib/createModuleIdFactory');
const deltaJSBundle = require('../deltaJSBundle');
function createModule(name, dependencies, type = 'module') {
function createModule(name, dependencies, type = 'js/module') {
return [
`/root/${name}.js`,
{
@ -24,7 +24,7 @@ function createModule(name, dependencies, type = 'module') {
{absolutePath: `/root/${dep}.js`, data: {isAsync: false, name: dep}},
]),
),
output: {type, code: `__d(function() {${name}()});`},
output: [{type, data: {code: `__d(function() {${name}()});`}}],
},
];
}

View File

@ -27,16 +27,16 @@ describe('getOrderedDependencyPaths', () => {
it('Should return all module dependencies correctly', async () => {
const graph = {
dependencies: new Map([
[1, {path: '/tmp/1.js', output: {type: 'js/module'}}],
[2, {path: '/tmp/2.js', output: {type: 'js/module'}}],
[3, {path: '/tmp/3.js', output: {type: 'js/module'}}],
[4, {path: '/tmp/4.js', output: {type: 'js/module'}}],
[1, {path: '/tmp/1.js', output: [{type: 'js/module'}]}],
[2, {path: '/tmp/2.js', output: [{type: 'js/module'}]}],
[3, {path: '/tmp/3.js', output: [{type: 'js/module'}]}],
[4, {path: '/tmp/4.js', output: [{type: 'js/module'}]}],
]),
};
expect(
await getAllFiles(
[{path: '/tmp/0.js', output: {type: 'js/module'}}],
[{path: '/tmp/0.js', output: [{type: 'js/module'}]}],
graph,
{},
),
@ -52,11 +52,11 @@ describe('getOrderedDependencyPaths', () => {
it('Should add assets data dependencies correctly', async () => {
const graph = {
dependencies: new Map([
[1, {path: '/tmp/1.js', output: {type: 'js/module'}}],
[2, {path: '/tmp/2.png', output: {type: 'js/module/asset'}}],
[3, {path: '/tmp/3.js', output: {type: 'js/module'}}],
[4, {path: '/tmp/4.png', output: {type: 'js/module/asset'}}],
[5, {path: '/tmp/5.js', output: {type: 'js/module'}}],
[1, {path: '/tmp/1.js', output: [{type: 'js/module'}]}],
[2, {path: '/tmp/2.png', output: [{type: 'js/module/asset'}]}],
[3, {path: '/tmp/3.js', output: [{type: 'js/module'}]}],
[4, {path: '/tmp/4.png', output: [{type: 'js/module/asset'}]}],
[5, {path: '/tmp/5.js', output: [{type: 'js/module'}]}],
]),
};

View File

@ -26,11 +26,11 @@ beforeEach(() => {
it('should return the bundle assets', async () => {
const graph = {
dependencies: new Map([
['/tmp/1.js', {path: '/tmp/1.js', output: {type: 'js/module'}}],
['/tmp/2.js', {path: '/tmp/2.js', output: {type: 'js/module'}}],
['/tmp/3.png', {path: '/tmp/3.png', output: {type: 'js/module/asset'}}],
['/tmp/4.js', {path: '/tmp/2.js', output: {type: 'js/module'}}],
['/tmp/5.mov', {path: '/tmp/5.mov', output: {type: 'js/module/asset'}}],
['/tmp/1.js', {path: '/tmp/1.js', output: [{type: 'js/module'}]}],
['/tmp/2.js', {path: '/tmp/2.js', output: [{type: 'js/module'}]}],
['/tmp/3.png', {path: '/tmp/3.png', output: [{type: 'js/module/asset'}]}],
['/tmp/4.js', {path: '/tmp/2.js', output: [{type: 'js/module'}]}],
['/tmp/5.mov', {path: '/tmp/5.mov', output: [{type: 'js/module/asset'}]}],
]),
};

View File

@ -23,7 +23,8 @@ function createModule(name, dependencies, type = 'js/module') {
{absolutePath: `/root/${dep}.js`, data: {isAsync: false, name: dep}},
]),
),
output: {type, code: `__d(function() {${name}()});`},
getSource: () => `source of ${name}`,
output: [{type, data: {code: `__d(function() {${name}()});`}}],
},
];
}

View File

@ -14,22 +14,28 @@ const createModuleIdFactory = require('../../../lib/createModuleIdFactory');
const plainJSBundle = require('../plainJSBundle');
const polyfill = {
output: {
type: 'js/script',
code: '__d(function() {/* code for polyfill */});',
},
output: [
{
type: 'js/script',
data: {code: '__d(function() {/* code for polyfill */});'},
},
],
};
const fooModule = {
path: 'foo',
dependencies: new Map([['./bar', {absolutePath: 'bar', data: {}}]]),
output: {type: 'js/module', code: '__d(function() {/* code for foo */});'},
output: [
{type: 'js/module', data: {code: '__d(function() {/* code for foo */});'}},
],
};
const barModule = {
path: 'bar',
dependencies: new Map(),
output: {type: 'js/module', code: '__d(function() {/* code for bar */});'},
output: [
{type: 'js/module', data: {code: '__d(function() {/* code for bar */});'}},
],
};
const getRunModuleStatement = moduleId =>

View File

@ -14,34 +14,46 @@ const sourceMapString = require('../sourceMapString');
const polyfill = {
path: '/root/pre.js',
output: {
type: 'js/script',
code: '__d(function() {/* code for polyfill */});',
map: [],
source: 'source pre',
},
getSource: () => 'source pre',
output: [
{
type: 'js/script',
data: {
code: '__d(function() {/* code for polyfill */});',
map: [],
},
},
],
};
const fooModule = {
path: '/root/foo.js',
dependencies: new Map([['./bar', 'bar']]),
output: {
type: 'js/module',
code: '__d(function() {/* code for foo */});',
map: [],
source: 'source foo',
},
getSource: () => 'source foo',
output: [
{
type: 'js/module',
data: {
code: '__d(function() {/* code for foo */});',
map: [],
},
},
],
};
const barModule = {
path: '/root/bar.js',
dependencies: new Map(),
output: {
type: 'js/module',
code: '__d(function() {/* code for bar */});',
map: [],
source: 'source bar',
},
getSource: () => 'source bar',
output: [
{
type: 'js/module',
data: {
code: '__d(function() {/* code for bar */});',
map: [],
},
},
],
};
it('should serialize a very simple bundle', () => {

View File

@ -13,6 +13,7 @@
const getAppendScripts = require('../../lib/getAppendScripts');
const {wrapModule} = require('./helpers/js');
const {getJsOutput, isJsModule} = require('./helpers/js');
import type {Delta, Graph} from '../../DeltaBundler';
import type {Module} from '../traverseDependencies';
@ -39,10 +40,12 @@ function deltaJSBundle(
const outputDelta = [];
for (const module of delta.modified.values()) {
outputDelta.push([
options.createModuleId(module.path),
wrapModule(module, options),
]);
if (isJsModule(module)) {
outputDelta.push([
options.createModuleId(module.path),
wrapModule(module, options),
]);
}
}
for (const path of delta.deleted) {
@ -53,17 +56,21 @@ function deltaJSBundle(
let i = -1;
for (const module of pre) {
outputPre.push([i, module.output.code]);
i--;
if (isJsModule(module)) {
outputPre.push([i, getJsOutput(module).data.code]);
i--;
}
}
const appendScripts = getAppendScripts(entryPoint, graph, options).values();
for (const module of appendScripts) {
outputPost.push([
options.createModuleId(module.path),
module.output.code,
]);
if (isJsModule(module)) {
outputPost.push([
options.createModuleId(module.path),
getJsOutput(module).data.code,
]);
}
}
}

View File

@ -11,6 +11,7 @@
'use strict';
const {getAssetFiles} = require('../../Assets');
const {getJsOutput, isJsModule} = require('./helpers/js');
import type {Graph} from '../DeltaCalculator';
import type {Module} from '../traverseDependencies';
@ -26,16 +27,25 @@ async function getAllFiles(
): Promise<$ReadOnlyArray<string>> {
const modules = graph.dependencies;
const dependencies = await Promise.all(
[...pre, ...modules.values()].map(async module => {
if (module.output.type !== 'js/module/asset') {
return [module.path];
} else {
return await getAssetFiles(module.path, options.platform);
}
}),
);
const promises = [];
for (const module of pre) {
promises.push([module.path]);
}
for (const module of modules.values()) {
if (!isJsModule(module)) {
continue;
}
if (getJsOutput(module).type === 'js/module/asset') {
promises.push(getAssetFiles(module.path, options.platform));
} else {
promises.push([module.path]);
}
}
const dependencies = await Promise.all(promises);
const output = [];
for (const dependencyArray of dependencies) {

View File

@ -13,6 +13,7 @@
const toLocalPath = require('../../node-haste/lib/toLocalPath');
const {getAssetData} = require('../../Assets');
const {getJsOutput, isJsModule} = require('./helpers/js');
import type {AssetData} from '../../Assets';
import type {Graph} from '../DeltaCalculator';
@ -27,21 +28,22 @@ async function getAssets(
graph: Graph,
options: Options,
): Promise<$ReadOnlyArray<AssetData>> {
const assets = await Promise.all(
Array.from(graph.dependencies.values()).map(async module => {
if (module.output.type === 'js/module/asset') {
return getAssetData(
const promises = [];
for (const module of graph.dependencies.values()) {
if (isJsModule(module) && getJsOutput(module).type === 'js/module/asset') {
promises.push(
getAssetData(
module.path,
toLocalPath(options.projectRoots, module.path),
options.assetPlugins,
options.platform,
);
}
return null;
}),
);
),
);
}
}
return assets.filter(Boolean);
return await Promise.all(promises);
}
module.exports = getAssets;

View File

@ -13,10 +13,11 @@
const fullSourceMapObject = require('./sourceMapObject');
const getAppendScripts = require('../../lib/getAppendScripts');
const getTransitiveDependencies = require('./helpers/getTransitiveDependencies');
const nullthrows = require('fbjs/lib/nullthrows');
const path = require('path');
const {createRamBundleGroups} = require('../../Bundler/util');
const {wrapModule} = require('./helpers/js');
const {isJsModule, wrapModule} = require('./helpers/js');
import type {GetTransformOptions} from '../../Bundler';
import type {ModuleTransportLike} from '../../shared/types.flow';
@ -56,7 +57,7 @@ async function getRamBundleInfo(
modules.forEach(module => options.createModuleId(module.path));
const ramModules = modules.map(module => ({
const ramModules = modules.filter(isJsModule).map(module => ({
id: options.createModuleId(module.path),
code: wrapModule(module, options),
map: fullSourceMapObject(
@ -68,8 +69,9 @@ async function getRamBundleInfo(
),
name: path.basename(module.path),
sourcePath: module.path,
source: module.output.source,
type: module.output.type,
source: module.getSource(),
type: nullthrows(module.output.find(({type}) => type.startsWith('js')))
.type,
}));
const {preloadedModules, ramGroups} = await _getRamOptions(

View File

@ -24,13 +24,18 @@ beforeEach(() => {
['bar', {absolutePath: '/bar', data: {isAsync: false, name: 'bar'}}],
['baz', {absolutePath: '/baz', data: {isAsync: false, name: 'baz'}}],
]),
getSource: () => '',
inverseDependencies: new Set(),
output: {
code: '__d(function() { console.log("foo") });',
map: [],
source: '',
type: 'js/module',
},
output: [
{
data: {
code: '__d(function() { console.log("foo") });',
map: [],
},
type: 'js/module',
},
],
};
});
@ -54,14 +59,14 @@ describe('wrapModule()', () => {
});
it('should not wrap a script', () => {
myModule.output.type = 'js/script';
myModule.output[0].type = 'js/script';
expect(
wrapModule(myModule, {
createModuleId: createModuleIdFactory(),
dev: true,
}),
).toEqual(myModule.output.code);
).toEqual(myModule.output[0].data.code);
});
it('should use custom createModuleId param', () => {

View File

@ -11,6 +11,7 @@
'use strict';
const addParamsToDefineCall = require('../../../lib/addParamsToDefineCall');
const invariant = require('fbjs/lib/invariant');
const path = require('path');
import type {Module} from '../../traverseDependencies';
@ -26,8 +27,9 @@ export type Options = {
const PASS_MODULE_PATHS_TO_DEFINE = false;
function wrapModule(module: Module, options: Options) {
if (module.output.type.startsWith('js/script')) {
return module.output.code;
const output = getJsOutput(module);
if (output.type.startsWith('js/script')) {
return output.data.code;
}
const moduleId = options.createModuleId(module.path);
@ -49,9 +51,28 @@ function wrapModule(module: Module, options: Options) {
}
}
return addParamsToDefineCall(module.output.code, ...params);
return addParamsToDefineCall(output.data.code, ...params);
}
function getJsOutput(module: Module) {
const jsModules = module.output.filter(({type}) => type.startsWith('js/'));
invariant(
jsModules.length === 1,
`Modules must have exactly one JS output, but ${module.path} has ${
jsModules.length
} JS outputs.`,
);
return jsModules[0];
}
function isJsModule(module: Module) {
return module.output.some(output => output.type.startsWith('js/'));
}
module.exports = {
getJsOutput,
isJsModule,
wrapModule,
};

View File

@ -12,7 +12,7 @@
const addParamsToDefineCall = require('../../lib/addParamsToDefineCall');
const {wrapModule} = require('./helpers/js');
const {isJsModule, wrapModule} = require('./helpers/js');
import type {Delta, Graph} from '../../DeltaBundler';
import type {Module} from '../traverseDependencies';
@ -34,7 +34,9 @@ function hmrJSBundle(delta: Delta, graph: Graph, options: Options): Result {
const modules = [];
for (const module of delta.modified.values()) {
modules.push(_prepareModule(module, graph, options));
if (isJsModule(module)) {
modules.push(_prepareModule(module, graph, options));
}
}
return {

View File

@ -12,7 +12,7 @@
const getAppendScripts = require('../../lib/getAppendScripts');
const {wrapModule} = require('./helpers/js');
const {isJsModule, wrapModule} = require('./helpers/js');
import type {Graph} from '../DeltaCalculator';
import type {Module} from '../traverseDependencies';
@ -41,6 +41,7 @@ function plainJSBundle(
...graph.dependencies.values(),
...getAppendScripts(entryPoint, graph, options),
]
.filter(isJsModule)
.map(module => wrapModule(module, options))
.join('\n');
}

View File

@ -10,6 +10,7 @@
'use strict';
const {isJsModule, getJsOutput} = require('./helpers/js');
const {fromRawMappings} = require('metro-source-map');
import type {Graph} from '../DeltaCalculator';
@ -21,12 +22,15 @@ function fullSourceMapObject(
graph: Graph,
options: {|+excludeSource: boolean|},
): BabelSourceMap {
const modules = [...pre, ...graph.dependencies.values()].map(module => {
return {
...module.output,
path: module.path,
};
});
const modules = [...pre, ...graph.dependencies.values()]
.filter(isJsModule)
.map(module => {
return {
...getJsOutput(module).data,
path: module.path,
source: options.excludeSource ? '' : module.getSource(),
};
});
return fromRawMappings(modules).toMap(undefined, {
excludeSource: options.excludeSource,

View File

@ -10,6 +10,7 @@
'use strict';
const {isJsModule, getJsOutput} = require('./helpers/js');
const {fromRawMappings} = require('metro-source-map');
import type {Graph} from '../DeltaCalculator';
@ -20,12 +21,15 @@ function fullSourceMap(
graph: Graph,
options: {|+excludeSource: boolean|},
): string {
const modules = [...pre, ...graph.dependencies.values()].map(module => {
return {
...module.output,
path: module.path,
};
});
const modules = [...pre, ...graph.dependencies.values()]
.filter(isJsModule)
.map(module => {
return {
...getJsOutput(module).data,
path: module.path,
source: options.excludeSource ? '' : module.getSource(),
};
});
return fromRawMappings(modules).toString(undefined, {
excludeSource: options.excludeSource,

View File

@ -13,13 +13,17 @@ Object {
},
},
},
"getSource": [Function],
"inverseDependencies": Set {},
"output": Object {
"code": "// code",
"map": Array [],
"source": "// source",
"type": "js/module",
},
"output": Array [
Object {
"data": Object {
"code": "// code",
"map": Array [],
},
"type": "js/module",
},
],
"path": "/bundle",
},
"/foo" => Object {
@ -39,41 +43,53 @@ Object {
},
},
},
"getSource": [Function],
"inverseDependencies": Set {
"/bundle",
},
"output": Object {
"code": "// code",
"map": Array [],
"source": "// source",
"type": "js/module",
},
"output": Array [
Object {
"data": Object {
"code": "// code",
"map": Array [],
},
"type": "js/module",
},
],
"path": "/foo",
},
"/bar" => Object {
"dependencies": Map {},
"getSource": [Function],
"inverseDependencies": Set {
"/foo",
},
"output": Object {
"code": "// code",
"map": Array [],
"source": "// source",
"type": "js/module",
},
"output": Array [
Object {
"data": Object {
"code": "// code",
"map": Array [],
},
"type": "js/module",
},
],
"path": "/bar",
},
"/baz" => Object {
"dependencies": Map {},
"getSource": [Function],
"inverseDependencies": Set {
"/foo",
},
"output": Object {
"code": "// code",
"map": Array [],
"source": "// source",
"type": "js/module",
},
"output": Array [
Object {
"data": Object {
"code": "// code",
"map": Array [],
},
"type": "js/module",
},
],
"path": "/baz",
},
},

View File

@ -136,12 +136,16 @@ beforeEach(async () => {
name: dep.name,
isAsync: false,
})),
output: {
code: '// code',
map: [],
source: '// source',
type: 'js/module',
},
getSource: () => '// source',
output: [
{
data: {
code: '// code',
map: [],
},
type: 'js/module',
},
],
};
},
onProgress: null,

View File

@ -13,8 +13,6 @@
import type {TransformResultDependency} from '../ModuleGraph/types.flow';
import type {MetroSourceMapSegmentTuple} from 'metro-source-map';
export type DependencyType = string;
export type Dependency = {|
absolutePath: string,
data: TransformResultDependency,
@ -23,13 +21,9 @@ export type Dependency = {|
export type Module = {|
dependencies: Map<string, Dependency>,
inverseDependencies: Set<string>,
output: TransformOutput,
path: string,
output: {
+code: string,
+map: Array<MetroSourceMapSegmentTuple>,
+source: string,
+type: DependencyType,
},
getSource: () => string,
|};
export type Graph = {|
@ -51,15 +45,19 @@ type Delta = {
deleted: Set<string>,
};
export type TransformFn = string => Promise<{
dependencies: $ReadOnlyArray<TransformResultDependency>,
output: {
export type TransformOutput = $ReadOnlyArray<{|
+data: {
+code: string,
+map: Array<MetroSourceMapSegmentTuple>,
+source: string,
+type: DependencyType,
},
}>;
+type: string,
|}>;
export type TransformFn = string => Promise<{|
dependencies: $ReadOnlyArray<TransformResultDependency>,
output: TransformOutput,
+getSource: () => string,
|}>;
export type Options = {|
resolve: (from: string, to: string) => string,
@ -203,6 +201,7 @@ async function processModule(
);
// Update the module information.
module.getSource = result.getSource;
module.output = result.output;
module.dependencies = new Map();
@ -315,12 +314,8 @@ function createModule(filePath: string, graph: Graph): Module {
dependencies: new Map(),
inverseDependencies: new Set(),
path: filePath,
output: {
code: '',
map: [],
source: '',
type: 'js/module',
},
getSource: () => '',
output: [],
};
graph.dependencies.set(filePath, module);

View File

@ -92,10 +92,14 @@ describe('HmrServer', () => {
dependencies: new Map(),
inverseDependencies: new Set(),
path: '/hi',
output: {
code: '__d(function() { alert("hi"); });',
type: 'js/module',
},
output: [
{
type: 'js/module',
data: {
code: '__d(function() { alert("hi"); });',
},
},
],
},
],
]),

View File

@ -108,12 +108,16 @@ describe('processRequest', () => {
},
],
]),
output: {
type: 'js/module',
code: '__d(function() {entry();});',
map: [],
source: 'code-mybundle',
},
getSource: () => 'code-mybundle',
output: [
{
type: 'js/module',
data: {
code: '__d(function() {entry();});',
map: [],
},
},
],
},
],
[
@ -121,12 +125,16 @@ describe('processRequest', () => {
{
path: '/root/foo.js',
dependencies: new Map(),
output: {
type: 'js/module',
code: '__d(function() {foo();});',
map: [],
source: 'code-foo',
},
getSource: () => 'code-foo',
output: [
{
type: 'js/module',
data: {
code: '__d(function() {foo();});',
map: [],
},
},
],
},
],
]);
@ -160,12 +168,16 @@ describe('processRequest', () => {
{
path: 'require-js',
dependencies: new Map(),
output: {
type: 'js/script',
code: 'function () {require();}',
map: [],
source: 'code-require',
},
getSource: () => 'code-require',
output: [
{
type: 'js/script',
data: {
code: 'function () {require();}',
map: [],
},
},
],
},
]),
);
@ -461,11 +473,12 @@ describe('processRequest', () => {
'/root/foo.js',
{
path: '/root/foo.js',
output: {
type: 'js/module',
code: '__d(function() {modified();});',
map: [],
},
output: [
{
type: 'js/module',
data: {code: '__d(function() {modified();});'},
},
],
dependencies: new Map(),
},
],
@ -506,11 +519,12 @@ describe('processRequest', () => {
'/root/foo.js',
{
path: '/root/foo.js',
output: {
type: 'js/module',
code: '__d(function() {modified();});',
map: [],
},
output: [
{
type: 'js/module',
data: {code: '__d(function() {modified();});'},
},
],
dependencies: new Map(),
},
],

View File

@ -36,13 +36,19 @@ function getAppendScripts<T: number | string>(
output.push({
path: `require-${path}`,
dependencies: new Map(),
getSource: () => '',
inverseDependencies: new Set(),
output: {
code: options.getRunModuleStatement(options.createModuleId(path)),
source: '',
map: [],
type: 'js/script/virtual',
},
output: [
{
type: 'js/script/virtual',
data: {
code: options.getRunModuleStatement(
options.createModuleId(path),
),
map: [],
},
},
],
});
}
}
@ -52,13 +58,17 @@ function getAppendScripts<T: number | string>(
output.push({
path: 'source-map',
dependencies: new Map(),
getSource: () => '',
inverseDependencies: new Set(),
output: {
code: `//# sourceMappingURL=${options.sourceMapUrl}`,
source: '',
map: [],
type: 'js/script/virtual',
},
output: [
{
type: 'js/script/virtual',
data: {
code: `//# sourceMappingURL=${options.sourceMapUrl}`,
map: [],
},
},
],
});
}

View File

@ -86,14 +86,18 @@ function _getPrelude({dev}: {dev: boolean}): Module {
return {
dependencies: new Map(),
getSource: () => code,
inverseDependencies: new Set(),
path: name,
output: {
code,
map: [],
source: code,
type: 'js/script/virtual',
},
output: [
{
type: 'js/script/virtual',
data: {
code,
map: [],
},
},
],
};
}

View File

@ -109,25 +109,19 @@ async function getTransformFn(
),
});
// eslint-disable-next-line lint/flow-no-fixme
// $FlowFixMe: "defineProperty" with a getter is buggy in flow.
const output = {
code: result.code,
map: result.map,
type: result.type,
};
// Lazily access source code; if not needed, don't read the file.
// eslint-disable-next-line lint/flow-no-fixme
// $FlowFixMe: "defineProperty" with a getter is buggy in flow.
Object.defineProperty(output, 'source', {
configurable: true,
enumerable: true,
get: () => result.source,
});
return {
output,
getSource() {
return result.source;
},
output: [
{
data: {
code: result.code,
map: result.map,
},
type: result.type,
},
],
dependencies: result.dependencies,
};
};