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 {MetroSourceMapSegmentTuple} from 'metro-source-map';
|
||||
|
||||
export type DependencyType = 'module' | 'script' | 'asset';
|
||||
export type DependencyType = string;
|
||||
|
||||
export type Dependency = {|
|
||||
absolutePath: string,
|
||||
|
|
|
@ -42,6 +42,7 @@ export type TransformedCode = {
|
|||
code: string,
|
||||
dependencies: $ReadOnlyArray<TransformResultDependency>,
|
||||
map: Array<MetroSourceMapSegmentTuple>,
|
||||
type: string,
|
||||
};
|
||||
|
||||
export type TransformArgs<ExtraOptions: {}> = {|
|
||||
|
@ -140,6 +141,7 @@ async function transformCode(
|
|||
};
|
||||
|
||||
let data;
|
||||
let type = 'module';
|
||||
|
||||
if (sourceCode == null) {
|
||||
data = fs.readFileSync(filename);
|
||||
|
@ -171,7 +173,7 @@ async function transformCode(
|
|||
}
|
||||
|
||||
return {
|
||||
result: {dependencies: [], code, map},
|
||||
result: {dependencies: [], code, map, type},
|
||||
sha1,
|
||||
transformFileStartLogEntry,
|
||||
transformFileEndLogEntry,
|
||||
|
@ -193,7 +195,12 @@ async function transformCode(
|
|||
src: sourceCode,
|
||||
};
|
||||
|
||||
const transformResult = isAsset(filename, assetExts)
|
||||
if (isAsset(filename, assetExts)) {
|
||||
type = 'asset';
|
||||
}
|
||||
|
||||
const transformResult =
|
||||
type === 'asset'
|
||||
? await assetTransformer.transform(
|
||||
transformerArgs,
|
||||
assetRegistryPath,
|
||||
|
@ -220,6 +227,8 @@ async function transformCode(
|
|||
if (isScript) {
|
||||
dependencies = [];
|
||||
wrappedAst = JsFileWrapping.wrapPolyfill(ast);
|
||||
|
||||
type = 'script';
|
||||
} else {
|
||||
let dependencyMapName;
|
||||
try {
|
||||
|
@ -280,7 +289,7 @@ async function transformCode(
|
|||
}
|
||||
|
||||
return {
|
||||
result: {dependencies, code, map},
|
||||
result: {dependencies, code, map, type},
|
||||
sha1,
|
||||
transformFileStartLogEntry,
|
||||
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
|
||||
// $FlowFixMe: "defineProperty" with a getter is buggy in flow.
|
||||
const output = {
|
||||
code: result.code,
|
||||
map: result.map,
|
||||
type,
|
||||
type: result.type,
|
||||
};
|
||||
|
||||
// Lazily access source code; if not needed, don't read the file.
|
||||
|
|
|
@ -27,6 +27,7 @@ type ReadResult = {
|
|||
+dependencies: $ReadOnlyArray<TransformResultDependency>,
|
||||
+map: Array<MetroSourceMapSegmentTuple>,
|
||||
+source: string,
|
||||
+type: string,
|
||||
};
|
||||
|
||||
export type TransformCode = (
|
||||
|
@ -91,6 +92,7 @@ class Module {
|
|||
code: result.code,
|
||||
dependencies: result.dependencies,
|
||||
map: result.map,
|
||||
type: result.type,
|
||||
get source() {
|
||||
return module._readSourceCode();
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue