forked from embroider-build/embroider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request embroider-build#2029 from embroider-build/vite-opt…
…imize-test Reform extension searching and dep optimization
- Loading branch information
Showing
23 changed files
with
647 additions
and
774 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import V1Addon from '../v1-addon'; | ||
|
||
export default class extends V1Addon { | ||
get packageMeta() { | ||
let meta = super.packageMeta; | ||
if (meta['implicit-modules']) { | ||
// ember-resolver has a vestigial empty file here that existed due to | ||
// babel-plugin-debug-macros behavior. But ember-resolver no longer uses | ||
// babel-plugin-debug-macros. And the empty file makes vite's CJS interop | ||
// get confused and produce a runtime crash. | ||
meta['implicit-modules'] = meta['implicit-modules'].filter(m => m !== './features'); | ||
} | ||
return meta; | ||
} | ||
} |
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,50 @@ | ||
import { existsSync } from 'fs-extra'; | ||
import { cleanUrl } from './paths'; | ||
import type PackageCache from './package-cache'; | ||
import { sep } from 'path'; | ||
|
||
export function syntheticJStoHBS(source: string): string | null { | ||
// explicit js is the only case we care about here. Synthetic template JS is | ||
// only ever JS (never TS or anything else). And extensionless imports are | ||
// handled by the default resolving system doing extension search. | ||
if (cleanUrl(source, true).endsWith('.js')) { | ||
return source.replace(/.js(\?.*)?/, '.hbs$1'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export function needsSyntheticComponentJS( | ||
requestedSpecifier: string, | ||
foundFile: string, | ||
packageCache: Pick<PackageCache, 'ownerOfFile'> | ||
): string | null { | ||
requestedSpecifier = cleanUrl(requestedSpecifier, true); | ||
foundFile = cleanUrl(foundFile); | ||
if ( | ||
discoveredImplicitHBS(requestedSpecifier, foundFile) && | ||
!foundFile.split(sep).join('/').endsWith('/template.hbs') && | ||
!correspondingJSExists(foundFile) && | ||
isInComponents(foundFile, packageCache) | ||
) { | ||
return foundFile.slice(0, -3) + 'js'; | ||
} | ||
return null; | ||
} | ||
|
||
function discoveredImplicitHBS(source: string, id: string): boolean { | ||
return !source.endsWith('.hbs') && id.endsWith('.hbs'); | ||
} | ||
|
||
function correspondingJSExists(id: string): boolean { | ||
return ['js', 'ts'].some(ext => existsSync(id.slice(0, -3) + ext)); | ||
} | ||
|
||
function isInComponents(id: string, packageCache: Pick<PackageCache, 'ownerOfFile'>) { | ||
const pkg = packageCache.ownerOfFile(id); | ||
return pkg?.isV2App() && id.slice(pkg?.root.length).split(sep).join('/').startsWith('/components'); | ||
} | ||
|
||
export function templateOnlyComponentSource() { | ||
return `import templateOnly from '@ember/component/template-only';\nexport default templateOnly();\n`; | ||
} |
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
Oops, something went wrong.