Skip to content

Commit

Permalink
fix(babel): invalidate cache whenever it's possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Aug 30, 2023
1 parent b021c42 commit bc76ac0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
29 changes: 15 additions & 14 deletions packages/babel/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,6 @@ class Module {
}

const m = new Module(entrypoint, this.cache, this);

this.cache.add('entrypoints', entrypoint.name, {
evaluated: true,
evaluatedOnly: mergeOnly(entrypoint.evaluatedOnly, entrypoint.only),
exportsValues: entrypoint.exportsValues,
generation: entrypoint.generation + 1,
ignored: false,
log: entrypoint.log,
only: entrypoint.only,
});
m.evaluate();

return entrypoint.exports;
Expand All @@ -415,8 +405,19 @@ class Module {
);

evaluate(): void {
const source =
this.entrypoint.transformedCode ?? this.entrypoint.originalCode;
const { entrypoint } = this;

this.cache.add('entrypoints', entrypoint.name, {
evaluated: true,
evaluatedOnly: mergeOnly(entrypoint.evaluatedOnly, entrypoint.only),
exportsValues: entrypoint.exportsValues,
generation: entrypoint.generation + 1,
ignored: false,
log: entrypoint.log,
only: entrypoint.only,
});

const source = entrypoint.transformedCode ?? entrypoint.originalCode;

if (!source) {
this.debug(`evaluate`, 'there is nothing to evaluate');
Expand All @@ -443,10 +444,10 @@ class Module {

const { context, teardown } = createVmContext(
filename,
this.entrypoint.pluginOptions.features,
entrypoint.pluginOptions.features,
{
module: this,
exports: this.entrypoint.exports,
exports: entrypoint.exports,
require: this.require,
__linaria_dynamic_import: async (id: string) => this.require(id),
__dirname: path.dirname(filename),
Expand Down
8 changes: 7 additions & 1 deletion packages/babel/src/transform/generators/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { IWorkflowAction, SyncScenarioForAction } from '../types';
export function* workflow(
this: IWorkflowAction
): SyncScenarioForAction<IWorkflowAction> {
const { options } = this.services;
const { cache, options } = this.services;
const { entrypoint } = this;
if (entrypoint.ignored) {
return {
Expand All @@ -26,6 +26,12 @@ export function* workflow(

// File is ignored or does not contain any tags. Return original code.
if (!entrypoint.hasLinariaMetadata()) {
if (entrypoint.generation === 1) {
// 1st generation here means that it's __linariaPreval entrypoint
// without __linariaPreval, so we don't need it cached
cache.delete('entrypoints', entrypoint.name);
}

return {
code: originalCode,
sourceMap: options.inputSourceMap,
Expand Down

0 comments on commit bc76ac0

Please sign in to comment.