mirror of
https://github.com/status-im/metro.git
synced 2025-02-27 18:20:53 +00:00
Remove transformAndExtractDependencies() method in worker
Reviewed By: mjesun, davidaurelio Differential Revision: D6433590 fbshipit-source-id: ef3c31d73a831fabe2a6f1be6051b0cb5c7e6c55
This commit is contained in:
parent
86aba17329
commit
750e62bcdf
@ -63,7 +63,7 @@ describe('Transformer', function() {
|
||||
transformOptions,
|
||||
);
|
||||
|
||||
expect(api.transformAndExtractDependencies).toBeCalledWith(
|
||||
expect(api.transform).toBeCalledWith(
|
||||
transformModulePath,
|
||||
fileName,
|
||||
localPath,
|
||||
@ -78,7 +78,7 @@ describe('Transformer', function() {
|
||||
const message = 'message';
|
||||
const snippet = 'snippet';
|
||||
|
||||
api.transformAndExtractDependencies.mockImplementation(
|
||||
api.transform.mockImplementation(
|
||||
(transformPath, filename, localPth, code, opts) => {
|
||||
const babelError = new SyntaxError(message);
|
||||
|
||||
|
@ -22,14 +22,11 @@ import type {LocalPath} from '../node-haste/lib/toLocalPath';
|
||||
import type {MappingsMap} from '../lib/SourceMap';
|
||||
import type {ResultWithMap} from './worker/minify';
|
||||
|
||||
import typeof {
|
||||
minify as Minify,
|
||||
transformAndExtractDependencies as TransformAndExtractDependencies,
|
||||
} from './worker';
|
||||
import typeof {minify as Minify, transform as Transform} from './worker';
|
||||
|
||||
type WorkerInterface = Worker & {
|
||||
minify: Minify,
|
||||
transformAndExtractDependencies: TransformAndExtractDependencies,
|
||||
transform: Transform,
|
||||
};
|
||||
|
||||
type Reporters = {
|
||||
@ -52,7 +49,7 @@ module.exports = class Transformer {
|
||||
if (maxWorkers > 1) {
|
||||
this._worker = this._makeFarm(
|
||||
workerPath,
|
||||
['minify', 'transformAndExtractDependencies'],
|
||||
['minify', 'transform'],
|
||||
maxWorkers,
|
||||
);
|
||||
|
||||
@ -93,7 +90,7 @@ module.exports = class Transformer {
|
||||
try {
|
||||
debug('Started ransforming file', filename);
|
||||
|
||||
const data = await this._worker.transformAndExtractDependencies(
|
||||
const data = await this._worker.transform(
|
||||
this._transformModulePath,
|
||||
filename,
|
||||
localPath,
|
||||
@ -141,7 +138,6 @@ module.exports = class Transformer {
|
||||
_formatGenericError(err, filename) {
|
||||
const error = new TransformError(`${filename}: ${err.message}`);
|
||||
|
||||
// $FlowFixMe: extending an error.
|
||||
return Object.assign(error, {
|
||||
stack: (err.stack || '')
|
||||
.split('\n')
|
||||
|
@ -17,7 +17,7 @@ jest
|
||||
.mock('../minify');
|
||||
|
||||
const path = require('path');
|
||||
const transformCode = require('..').transformAndExtractDependencies;
|
||||
const transformCode = require('..').transform;
|
||||
|
||||
describe('code transformation worker:', () => {
|
||||
it('transforms a simple script', async () => {
|
||||
|
@ -93,7 +93,7 @@ function postTransform(
|
||||
options: Options,
|
||||
transformFileStartLogEntry: LogEntry,
|
||||
ast: Ast,
|
||||
) {
|
||||
): Data {
|
||||
const timeDelta = process.hrtime(transformFileStartLogEntry.start_timestamp);
|
||||
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
||||
const transformFileEndLogEntry = {
|
||||
@ -155,7 +155,7 @@ function postTransform(
|
||||
}
|
||||
|
||||
function transformCode(
|
||||
transformer: Transformer<*>,
|
||||
transformerPath: string,
|
||||
filename: string,
|
||||
localPath: LocalPath,
|
||||
sourceCode: string,
|
||||
@ -180,6 +180,8 @@ function transformCode(
|
||||
? []
|
||||
: [[inline.plugin, options], [constantFolding.plugin, options]];
|
||||
|
||||
// $FlowFixMe: impossible to type a dynamic require.
|
||||
const transformer: Transformer<*> = require(transformerPath);
|
||||
const transformResult = transformer.transform({
|
||||
filename,
|
||||
localPath,
|
||||
@ -202,11 +204,11 @@ function transformCode(
|
||||
: postTransform(...postTransformArgs, transformResult.ast);
|
||||
}
|
||||
|
||||
exports.minify = async function(
|
||||
function minifyCode(
|
||||
filename: string,
|
||||
code: string,
|
||||
sourceMap: MappingsMap,
|
||||
): Promise<ResultWithMap> {
|
||||
): ResultWithMap | Promise<ResultWithMap> {
|
||||
try {
|
||||
return minify.withSourceMap(code, sourceMap, filename);
|
||||
} catch (error) {
|
||||
@ -218,27 +220,9 @@ exports.minify = async function(
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
transform: transformCode,
|
||||
minify: minifyCode,
|
||||
};
|
||||
|
||||
exports.transformAndExtractDependencies = function(
|
||||
transform: string,
|
||||
filename: string,
|
||||
localPath: LocalPath,
|
||||
sourceCode: string,
|
||||
isScript: boolean,
|
||||
options: Options,
|
||||
): Data | Promise<Data> {
|
||||
// $FlowFixMe: impossible to type a dynamic require.
|
||||
const transformModule: Transformer<*> = require(transform);
|
||||
|
||||
return transformCode(
|
||||
transformModule,
|
||||
filename,
|
||||
localPath,
|
||||
sourceCode,
|
||||
isScript,
|
||||
options,
|
||||
);
|
||||
};
|
||||
|
||||
exports.transformCode = transformCode; // for easier testing
|
||||
|
Loading…
x
Reference in New Issue
Block a user