Skip to content

Commit

Permalink
Fix Placeholder cache solution when used with requireFile
Browse files Browse the repository at this point in the history
Ensure we include the package’s version in the configuration, so that the babel-loader can detect module version changes in it’s cache key consideration. Without this, installing a new node_module may not result in babel-loaders cache expiration occurring.
  • Loading branch information
stefanpenner committed Jun 9, 2021
1 parent 92f527e commit a45c8ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import partition from 'lodash/partition';
import mergeWith from 'lodash/mergeWith';
import cloneDeep from 'lodash/cloneDeep';
import type { Params as InlineBabelParams } from './babel-plugin-inline-hbs-node';
import { PortableHint, maybeNodeModuleVersion } from './portable';
import { PortableHint } from './portable';
import escapeRegExp from 'escape-string-regexp';
import { getEmberExports } from './load-ember-template-compiler';

Expand Down Expand Up @@ -922,7 +922,12 @@ export class AppBuilder<TreeNames> {
}
cursor = resolve.sync(target, { basedir: dirname(cursor) });
}
return { requireFile: cursor, useMethod: hint.useMethod, packageVersion: require(cursor).version};

return {
requireFile: cursor,
useMethod: hint.useMethod,
packageVersion: readJSONSync(cursor).version,
};
});
}

Expand Down
14 changes: 5 additions & 9 deletions packages/core/src/portable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mapValues from 'lodash/mapValues';
import assertNever from 'assert-never';
import { Memoize } from 'typescript-memoize';
import resolvePackagePath from 'resolve-package-path';
import { readJSONSync } from 'fs-extra';

export const protocol = '__embroider_portable_values__';
const { globalValues, nonce } = setupGlobals();
Expand All @@ -14,7 +15,7 @@ export interface PortableResult {

export interface PortableHint {
requireFile: string;
packageVersion: string | null,
packageVersion: string | undefined;
useMethod?: string;
}

Expand All @@ -25,10 +26,10 @@ export function maybeNodeModuleVersion(path: string) {

if (packagePath === null) {
// no package was found
return undefined; // should this bust the cache or ... ?
return undefined; // should this bust the cache or ... ?
} else {
// here we use `require` so that we mimic node's own module lifetime characteristics
return require(path).version;
return readJSONSync(packagePath).version;
}
}

Expand Down Expand Up @@ -196,7 +197,6 @@ function setupGlobals() {
return G[protocol];
}


// === broccoli-babel-transpiler support ===

function maybeBroccoli(object: any): BroccoliParallelPlaceholder | undefined {
Expand All @@ -212,8 +212,6 @@ function maybeBroccoli(object: any): BroccoliParallelPlaceholder | undefined {
return {
embroiderPlaceholder: true,
type: 'broccoli-parallel',

// try to grab node_module version
requireFile: object._parallelBabel.requireFile,
packageVersion: maybeNodeModuleVersion(object._parallelBabel.requireFile),
buildUsing: object._parallelBabel.buildUsing,
Expand Down Expand Up @@ -257,13 +255,11 @@ function maybeHTMLBars(object: any): HTMLBarsParallelPlaceholder | undefined {
typeof object.parallelBabel === 'object' &&
typeof object.parallelBabel.requireFile === 'string'
) {
debugger;
return {
embroiderPlaceholder: true,
type: 'htmlbars-parallel',
// try to grab node_module version
requireFile: object.parallelBabel.requireFile,
packageVersion: maybeNodeModuleVersion(object._parallelBabel.requireFile),
packageVersion: maybeNodeModuleVersion(object.parallelBabel.requireFile),
buildUsing: String(object.parallelBabel.buildUsing),
params: object.parallelBabel.params,
};
Expand Down

0 comments on commit a45c8ea

Please sign in to comment.