mirror of
https://github.com/status-im/metro.git
synced 2025-02-28 02:30:29 +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,
|
transformOptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(api.transformAndExtractDependencies).toBeCalledWith(
|
expect(api.transform).toBeCalledWith(
|
||||||
transformModulePath,
|
transformModulePath,
|
||||||
fileName,
|
fileName,
|
||||||
localPath,
|
localPath,
|
||||||
@ -78,7 +78,7 @@ describe('Transformer', function() {
|
|||||||
const message = 'message';
|
const message = 'message';
|
||||||
const snippet = 'snippet';
|
const snippet = 'snippet';
|
||||||
|
|
||||||
api.transformAndExtractDependencies.mockImplementation(
|
api.transform.mockImplementation(
|
||||||
(transformPath, filename, localPth, code, opts) => {
|
(transformPath, filename, localPth, code, opts) => {
|
||||||
const babelError = new SyntaxError(message);
|
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 {MappingsMap} from '../lib/SourceMap';
|
||||||
import type {ResultWithMap} from './worker/minify';
|
import type {ResultWithMap} from './worker/minify';
|
||||||
|
|
||||||
import typeof {
|
import typeof {minify as Minify, transform as Transform} from './worker';
|
||||||
minify as Minify,
|
|
||||||
transformAndExtractDependencies as TransformAndExtractDependencies,
|
|
||||||
} from './worker';
|
|
||||||
|
|
||||||
type WorkerInterface = Worker & {
|
type WorkerInterface = Worker & {
|
||||||
minify: Minify,
|
minify: Minify,
|
||||||
transformAndExtractDependencies: TransformAndExtractDependencies,
|
transform: Transform,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Reporters = {
|
type Reporters = {
|
||||||
@ -52,7 +49,7 @@ module.exports = class Transformer {
|
|||||||
if (maxWorkers > 1) {
|
if (maxWorkers > 1) {
|
||||||
this._worker = this._makeFarm(
|
this._worker = this._makeFarm(
|
||||||
workerPath,
|
workerPath,
|
||||||
['minify', 'transformAndExtractDependencies'],
|
['minify', 'transform'],
|
||||||
maxWorkers,
|
maxWorkers,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -93,7 +90,7 @@ module.exports = class Transformer {
|
|||||||
try {
|
try {
|
||||||
debug('Started ransforming file', filename);
|
debug('Started ransforming file', filename);
|
||||||
|
|
||||||
const data = await this._worker.transformAndExtractDependencies(
|
const data = await this._worker.transform(
|
||||||
this._transformModulePath,
|
this._transformModulePath,
|
||||||
filename,
|
filename,
|
||||||
localPath,
|
localPath,
|
||||||
@ -141,7 +138,6 @@ module.exports = class Transformer {
|
|||||||
_formatGenericError(err, filename) {
|
_formatGenericError(err, filename) {
|
||||||
const error = new TransformError(`${filename}: ${err.message}`);
|
const error = new TransformError(`${filename}: ${err.message}`);
|
||||||
|
|
||||||
// $FlowFixMe: extending an error.
|
|
||||||
return Object.assign(error, {
|
return Object.assign(error, {
|
||||||
stack: (err.stack || '')
|
stack: (err.stack || '')
|
||||||
.split('\n')
|
.split('\n')
|
||||||
|
@ -17,7 +17,7 @@ jest
|
|||||||
.mock('../minify');
|
.mock('../minify');
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const transformCode = require('..').transformAndExtractDependencies;
|
const transformCode = require('..').transform;
|
||||||
|
|
||||||
describe('code transformation worker:', () => {
|
describe('code transformation worker:', () => {
|
||||||
it('transforms a simple script', async () => {
|
it('transforms a simple script', async () => {
|
||||||
|
@ -93,7 +93,7 @@ function postTransform(
|
|||||||
options: Options,
|
options: Options,
|
||||||
transformFileStartLogEntry: LogEntry,
|
transformFileStartLogEntry: LogEntry,
|
||||||
ast: Ast,
|
ast: Ast,
|
||||||
) {
|
): Data {
|
||||||
const timeDelta = process.hrtime(transformFileStartLogEntry.start_timestamp);
|
const timeDelta = process.hrtime(transformFileStartLogEntry.start_timestamp);
|
||||||
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
||||||
const transformFileEndLogEntry = {
|
const transformFileEndLogEntry = {
|
||||||
@ -155,7 +155,7 @@ function postTransform(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function transformCode(
|
function transformCode(
|
||||||
transformer: Transformer<*>,
|
transformerPath: string,
|
||||||
filename: string,
|
filename: string,
|
||||||
localPath: LocalPath,
|
localPath: LocalPath,
|
||||||
sourceCode: string,
|
sourceCode: string,
|
||||||
@ -180,6 +180,8 @@ function transformCode(
|
|||||||
? []
|
? []
|
||||||
: [[inline.plugin, options], [constantFolding.plugin, options]];
|
: [[inline.plugin, options], [constantFolding.plugin, options]];
|
||||||
|
|
||||||
|
// $FlowFixMe: impossible to type a dynamic require.
|
||||||
|
const transformer: Transformer<*> = require(transformerPath);
|
||||||
const transformResult = transformer.transform({
|
const transformResult = transformer.transform({
|
||||||
filename,
|
filename,
|
||||||
localPath,
|
localPath,
|
||||||
@ -202,11 +204,11 @@ function transformCode(
|
|||||||
: postTransform(...postTransformArgs, transformResult.ast);
|
: postTransform(...postTransformArgs, transformResult.ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.minify = async function(
|
function minifyCode(
|
||||||
filename: string,
|
filename: string,
|
||||||
code: string,
|
code: string,
|
||||||
sourceMap: MappingsMap,
|
sourceMap: MappingsMap,
|
||||||
): Promise<ResultWithMap> {
|
): ResultWithMap | Promise<ResultWithMap> {
|
||||||
try {
|
try {
|
||||||
return minify.withSourceMap(code, sourceMap, filename);
|
return minify.withSourceMap(code, sourceMap, filename);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -218,27 +220,9 @@ exports.minify = async function(
|
|||||||
|
|
||||||
throw error;
|
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