-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure babel transpilation cache is invalided when changing versions of babel plugins or AST transforms #841
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function makePlugin(): any { | ||
stefanpenner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Dear future @rwjblue, | ||
stefanpenner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// This plugin exists as a sentinel plugin which has no behavior, but | ||
// provides a position in the babel configuration to include cache busting | ||
// meta-data about other plugins. Specifically their versions. | ||
// | ||
// Yours sincerely, | ||
// Contributor | ||
return {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import mapValues from 'lodash/mapValues'; | ||
import assertNever from 'assert-never'; | ||
import { Memoize } from 'typescript-memoize'; | ||
import resolvePackagePath from 'resolve-package-path'; | ||
|
||
export const protocol = '__embroider_portable_values__'; | ||
const { globalValues, nonce } = setupGlobals(); | ||
|
@@ -13,9 +14,22 @@ export interface PortableResult { | |
|
||
export interface PortableHint { | ||
requireFile: string; | ||
packageVersion: string | undefined; | ||
useMethod?: string; | ||
} | ||
|
||
const { findUpPackagePath } = resolvePackagePath; | ||
|
||
export function maybeNodeModuleVersion(path: string) { | ||
stefanpenner marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes 1 |
||
const packagePath = findUpPackagePath(path); | ||
|
||
if (packagePath === null) { | ||
throw new Error(`Could not find package.json for '${path}'`); | ||
stefanpenner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
return require(packagePath).version; // eslint-disable-line @typescript-eslint/no-require-imports | ||
} | ||
} | ||
|
||
export class Portable { | ||
constructor( | ||
private opts: { | ||
|
@@ -83,6 +97,7 @@ export class Portable { | |
embroiderPlaceholder: true, | ||
type: 'broccoli-parallel', | ||
requireFile: found.requireFile, | ||
packageVersion: maybeNodeModuleVersion(found.requireFile), | ||
useMethod: found.useMethod, | ||
}, | ||
isParallelSafe: true, | ||
|
@@ -154,6 +169,7 @@ interface BroccoliParallelPlaceholder { | |
embroiderPlaceholder: true; | ||
type: 'broccoli-parallel'; | ||
requireFile: string; | ||
packageVersion: string | undefined; | ||
useMethod: string | undefined; | ||
buildUsing: string | undefined; | ||
params: any; | ||
|
@@ -162,6 +178,7 @@ interface BroccoliParallelPlaceholder { | |
interface HTMLBarsParallelPlaceholder { | ||
embroiderPlaceholder: true; | ||
type: 'htmlbars-parallel'; | ||
packageVersion: string | undefined; | ||
requireFile: string; | ||
buildUsing: string; | ||
params: any; | ||
|
@@ -193,6 +210,7 @@ function maybeBroccoli(object: any): BroccoliParallelPlaceholder | undefined { | |
embroiderPlaceholder: true, | ||
type: 'broccoli-parallel', | ||
requireFile: object._parallelBabel.requireFile, | ||
packageVersion: maybeNodeModuleVersion(object._parallelBabel.requireFile), | ||
buildUsing: object._parallelBabel.buildUsing, | ||
useMethod: object._parallelBabel.useMethod, | ||
params: object._parallelBabel.params, | ||
|
@@ -238,6 +256,7 @@ function maybeHTMLBars(object: any): HTMLBarsParallelPlaceholder | undefined { | |
embroiderPlaceholder: true, | ||
type: 'htmlbars-parallel', | ||
requireFile: object.parallelBabel.requireFile, | ||
packageVersion: maybeNodeModuleVersion(object.parallelBabel.requireFile), | ||
buildUsing: String(object.parallelBabel.buildUsing), | ||
params: object.parallelBabel.params, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { maybeNodeModuleVersion } from '../src/portable'; | ||
import { readJSONSync } from 'fs-extra'; | ||
|
||
const EMBROIDER_CORE_VERSION = readJSONSync(`${__dirname}/../package.json`).version; | ||
|
||
describe('maybeNodeModuleVersion', () => { | ||
test('it', () => { | ||
expect(() => maybeNodeModuleVersion('/dev/null')).toThrow(/Could not find package.json for '\/dev\/null'/); | ||
expect(() => maybeNodeModuleVersion('/does/not/exist')).toThrow( | ||
/Could not find package.json for '\/does\/not\/exist'/ | ||
); | ||
expect(maybeNodeModuleVersion(__dirname)).toEqual(EMBROIDER_CORE_VERSION); | ||
expect(maybeNodeModuleVersion(__filename)).toEqual(EMBROIDER_CORE_VERSION); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fixes (2)