Skip to content

Commit

Permalink
Remove postProcess (#5674)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper committed Jan 19, 2021
1 parent 5536837 commit 8927696
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 79 deletions.
74 changes: 2 additions & 72 deletions packages/core/core/src/Transformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ import {optionsProxy} from './utils';

type GenerateFunc = (input: UncommittedAsset) => Promise<GenerateOutput>;

type PostProcessFunc = (
Array<UncommittedAsset>,
) => Promise<Array<UncommittedAsset> | null>;

export type TransformationOpts = {|
options: ParcelOptions,
config: ParcelConfig,
Expand Down Expand Up @@ -296,41 +292,7 @@ export default class Transformation {
}
}

if (!pipeline.postProcess) {
return finalAssets;
}

let processedCacheEntry = await this.readFromCache(
this.getCacheKey(
finalAssets,
pipeline.configs,
await getInvalidationHash(
finalAssets.flatMap(asset => asset.getInvalidations()),
this.options,
),
),
);

invariant(pipeline.postProcess != null);
let processedFinalAssets: Array<UncommittedAsset> =
processedCacheEntry ?? (await pipeline.postProcess(finalAssets)) ?? [];

if (!processedCacheEntry) {
await this.writeToCache(
this.getCacheKey(
processedFinalAssets,
pipeline.configs,
await getInvalidationHash(
processedFinalAssets.flatMap(asset => asset.getInvalidations()),
this.options,
),
),
processedFinalAssets,
pipeline.configs,
);
}

return processedFinalAssets;
return finalAssets;
}

async runPipeline(
Expand Down Expand Up @@ -369,8 +331,6 @@ export default class Transformation {
transformer.plugin,
transformer.name,
transformer.config,
transformer.configKeyPath,
this.parcelConfig,
);

for (let result of transformerResults) {
Expand Down Expand Up @@ -611,7 +571,6 @@ type Pipeline = {|
pluginOptions: PluginOptions,
resolverRunner: ResolverRunner,
workerApi: WorkerApi,
postProcess?: PostProcessFunc,
generate?: GenerateFunc,
|};

Expand All @@ -628,8 +587,6 @@ async function runTransformer(
transformer: Transformer,
transformerName: string,
preloadedConfig: ?Config,
configKeyPath: string,
parcelConfig: ParcelConfig,
): Promise<Array<TransformerResult>> {
const logger = new PluginLogger({origin: transformerName});

Expand Down Expand Up @@ -694,7 +651,7 @@ async function runTransformer(
}),
);

// Create generate and postProcess functions that can be called later
// Create generate functions that can be called later
pipeline.generate = (input: UncommittedAsset): Promise<GenerateOutput> => {
if (transformer.generate && input.ast) {
let generated = transformer.generate({
Expand All @@ -712,33 +669,6 @@ async function runTransformer(
);
};

// For Flow
let postProcess = transformer.postProcess;
if (postProcess) {
pipeline.postProcess = async (
assets: Array<UncommittedAsset>,
): Promise<Array<UncommittedAsset> | null> => {
let results = await postProcess.call(transformer, {
assets: assets.map(asset => new MutableAsset(asset)),
config,
options: pipeline.pluginOptions,
resolve,
logger,
});

return Promise.all(
results.map(result =>
asset.createChildAsset(
result,
transformerName,
parcelConfig.filePath,
configKeyPath,
),
),
);
};
}

return results;
}

Expand Down
7 changes: 0 additions & 7 deletions packages/core/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,6 @@ export type Transformer = {|
options: PluginOptions,
logger: PluginLogger,
|}) => Async<GenerateOutput>,
postProcess?: ({|
assets: Array<MutableAsset>,
config: ?ConfigResult,
resolve: ResolveFn,
options: PluginOptions,
logger: PluginLogger,
|}) => Async<Array<TransformerResult>>,
|};

/**
Expand Down

0 comments on commit 8927696

Please sign in to comment.