mirror of https://github.com/status-im/metro.git
Move type calculation to the worker
Reviewed By: davidaurelio Differential Revision: D7877465 fbshipit-source-id: b5b444e383363ae3b80f5fe099d99203435b8d69
This commit is contained in:
parent
192e1080ab
commit
94f531ad79
|
@ -13,7 +13,7 @@
|
||||||
import type {TransformResultDependency} from '../ModuleGraph/types.flow';
|
import type {TransformResultDependency} from '../ModuleGraph/types.flow';
|
||||||
import type {MetroSourceMapSegmentTuple} from 'metro-source-map';
|
import type {MetroSourceMapSegmentTuple} from 'metro-source-map';
|
||||||
|
|
||||||
export type DependencyType = 'module' | 'script' | 'asset';
|
export type DependencyType = string;
|
||||||
|
|
||||||
export type Dependency = {|
|
export type Dependency = {|
|
||||||
absolutePath: string,
|
absolutePath: string,
|
||||||
|
|
|
@ -42,6 +42,7 @@ export type TransformedCode = {
|
||||||
code: string,
|
code: string,
|
||||||
dependencies: $ReadOnlyArray<TransformResultDependency>,
|
dependencies: $ReadOnlyArray<TransformResultDependency>,
|
||||||
map: Array<MetroSourceMapSegmentTuple>,
|
map: Array<MetroSourceMapSegmentTuple>,
|
||||||
|
type: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TransformArgs<ExtraOptions: {}> = {|
|
export type TransformArgs<ExtraOptions: {}> = {|
|
||||||
|
@ -140,6 +141,7 @@ async function transformCode(
|
||||||
};
|
};
|
||||||
|
|
||||||
let data;
|
let data;
|
||||||
|
let type = 'module';
|
||||||
|
|
||||||
if (sourceCode == null) {
|
if (sourceCode == null) {
|
||||||
data = fs.readFileSync(filename);
|
data = fs.readFileSync(filename);
|
||||||
|
@ -171,7 +173,7 @@ async function transformCode(
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: {dependencies: [], code, map},
|
result: {dependencies: [], code, map, type},
|
||||||
sha1,
|
sha1,
|
||||||
transformFileStartLogEntry,
|
transformFileStartLogEntry,
|
||||||
transformFileEndLogEntry,
|
transformFileEndLogEntry,
|
||||||
|
@ -193,13 +195,18 @@ async function transformCode(
|
||||||
src: sourceCode,
|
src: sourceCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
const transformResult = isAsset(filename, assetExts)
|
if (isAsset(filename, assetExts)) {
|
||||||
? await assetTransformer.transform(
|
type = 'asset';
|
||||||
transformerArgs,
|
}
|
||||||
assetRegistryPath,
|
|
||||||
options.assetDataPlugins,
|
const transformResult =
|
||||||
)
|
type === 'asset'
|
||||||
: await transformer.transform(transformerArgs);
|
? await assetTransformer.transform(
|
||||||
|
transformerArgs,
|
||||||
|
assetRegistryPath,
|
||||||
|
options.assetDataPlugins,
|
||||||
|
)
|
||||||
|
: await transformer.transform(transformerArgs);
|
||||||
|
|
||||||
// Transformers can ouptut null ASTs (if they ignore the file). In that case
|
// Transformers can ouptut null ASTs (if they ignore the file). In that case
|
||||||
// we need to parse the module source code to get their AST.
|
// we need to parse the module source code to get their AST.
|
||||||
|
@ -220,6 +227,8 @@ async function transformCode(
|
||||||
if (isScript) {
|
if (isScript) {
|
||||||
dependencies = [];
|
dependencies = [];
|
||||||
wrappedAst = JsFileWrapping.wrapPolyfill(ast);
|
wrappedAst = JsFileWrapping.wrapPolyfill(ast);
|
||||||
|
|
||||||
|
type = 'script';
|
||||||
} else {
|
} else {
|
||||||
let dependencyMapName;
|
let dependencyMapName;
|
||||||
try {
|
try {
|
||||||
|
@ -280,7 +289,7 @@ async function transformCode(
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: {dependencies, code, map},
|
result: {dependencies, code, map, type},
|
||||||
sha1,
|
sha1,
|
||||||
transformFileStartLogEntry,
|
transformFileStartLogEntry,
|
||||||
transformFileEndLogEntry,
|
transformFileEndLogEntry,
|
||||||
|
|
|
@ -109,20 +109,12 @@ async function getTransformFn(
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
let type = 'module';
|
|
||||||
if (module.isAsset()) {
|
|
||||||
type = 'asset';
|
|
||||||
}
|
|
||||||
if (module.isPolyfill()) {
|
|
||||||
type = 'script';
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line lint/flow-no-fixme
|
// eslint-disable-next-line lint/flow-no-fixme
|
||||||
// $FlowFixMe: "defineProperty" with a getter is buggy in flow.
|
// $FlowFixMe: "defineProperty" with a getter is buggy in flow.
|
||||||
const output = {
|
const output = {
|
||||||
code: result.code,
|
code: result.code,
|
||||||
map: result.map,
|
map: result.map,
|
||||||
type,
|
type: result.type,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Lazily access source code; if not needed, don't read the file.
|
// Lazily access source code; if not needed, don't read the file.
|
||||||
|
|
|
@ -27,6 +27,7 @@ type ReadResult = {
|
||||||
+dependencies: $ReadOnlyArray<TransformResultDependency>,
|
+dependencies: $ReadOnlyArray<TransformResultDependency>,
|
||||||
+map: Array<MetroSourceMapSegmentTuple>,
|
+map: Array<MetroSourceMapSegmentTuple>,
|
||||||
+source: string,
|
+source: string,
|
||||||
|
+type: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TransformCode = (
|
export type TransformCode = (
|
||||||
|
@ -91,6 +92,7 @@ class Module {
|
||||||
code: result.code,
|
code: result.code,
|
||||||
dependencies: result.dependencies,
|
dependencies: result.dependencies,
|
||||||
map: result.map,
|
map: result.map,
|
||||||
|
type: result.type,
|
||||||
get source() {
|
get source() {
|
||||||
return module._readSourceCode();
|
return module._readSourceCode();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue