-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Reform internal use of template compiler #20587
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,4 @@ | ||
'use strict'; | ||
|
||
const Filter = require('broccoli-persistent-filter'); | ||
const { stripIndent } = require('common-tags'); | ||
|
||
GlimmerTemplatePrecompiler.prototype = Object.create(Filter.prototype); | ||
|
||
function GlimmerTemplatePrecompiler(inputTree, options) { | ||
if (!(this instanceof GlimmerTemplatePrecompiler)) { | ||
return new GlimmerTemplatePrecompiler(inputTree, options); | ||
} | ||
|
||
Filter.call(this, inputTree, {}); | ||
|
||
this.inputTree = inputTree; | ||
if (!options.glimmer) { | ||
throw new Error('No glimmer option provided!'); | ||
} | ||
this.precompile = options.glimmer.precompile; | ||
} | ||
|
||
GlimmerTemplatePrecompiler.prototype.extensions = ['hbs']; | ||
GlimmerTemplatePrecompiler.prototype.targetExtension = 'js'; | ||
|
||
GlimmerTemplatePrecompiler.prototype.baseDir = function () { | ||
return __dirname; | ||
}; | ||
|
||
GlimmerTemplatePrecompiler.prototype.processString = function (content, relativePath) { | ||
let compiled = this.precompile(content, { | ||
meta: { moduleName: relativePath }, | ||
}); | ||
return stripIndent` | ||
import { templateFactory } from '@glimmer/opcode-compiler'; | ||
export default templateFactory(${compiled}); | ||
`; | ||
}; | ||
|
||
module.exports = GlimmerTemplatePrecompiler; | ||
require('@swc-node/register'); | ||
module.exports = require('../packages/ember-template-compiler/minimal.ts'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,16 +65,21 @@ module.exports = function ({ project }) { | |
let emberBundles = withTargets(project, emberSource.buildEmberBundles.bind(emberSource)); | ||
|
||
let packages = debugTree( | ||
new MergeTrees([ | ||
// dynamically generated packages | ||
emberVersionES(), | ||
new MergeTrees( | ||
[ | ||
// packages/** (after typescript compilation) | ||
getPackagesES(), | ||
|
||
// packages/** (after typescript compilation) | ||
getPackagesES(), | ||
emberVersionES(), | ||
|
||
// externalized helpers | ||
babelHelpers(), | ||
]), | ||
// externalized helpers | ||
babelHelpers(), | ||
], | ||
{ | ||
// we're replacing the ember/verion file with the actual version number | ||
overwrite: true, | ||
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. The template compiler imports the version. Previously that would die because the version file is dynamically created. Now we have a placeholder file on disk that gets replaced in the build, so that our internal usage of template compiler doesn't die. |
||
} | ||
), | ||
'packages:initial' | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,17 @@ module.exports = { | |
let isEmberSource = this.project.name() === 'ember-source'; | ||
let babelHelperPlugin = injectBabelHelpers(isEmberSource); | ||
|
||
let compilerPath; | ||
if (isEmberSource) { | ||
// Here we are using the template compiler by directly evaluating it in | ||
// node, because we *are* the build that produces | ||
// ember-template-compiler.js. | ||
compilerPath = path.resolve(__dirname, '../broccoli/glimmer-template-compiler'); | ||
} else { | ||
// When we're building an app, we use the already built template compiler. | ||
compilerPath = path.resolve(__dirname, '../dist/ember-template-compiler.js'); | ||
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. This keeps the exact old behavior when building apps, and only changes the behavior when ember is building itself. |
||
} | ||
|
||
let options = { | ||
'ember-cli-babel': { | ||
disableDebugTooling: true, | ||
|
@@ -155,6 +166,7 @@ module.exports = { | |
plugins: [ | ||
babelHelperPlugin, | ||
buildDebugMacroPlugin(!isProduction), | ||
['babel-plugin-ember-template-compilation', { compilerPath }], | ||
...vmBabelPlugins({ isDebug: !isProduction }), | ||
], | ||
}), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,8 @@ | |
"@embroider/shared-internals": "^2.5.0", | ||
"@rollup/plugin-babel": "^6.0.3", | ||
"@simple-dom/document": "^1.4.0", | ||
"@swc/core": "^1.3.100", | ||
"@swc-node/register": "^1.6.8", | ||
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. This is how we can directly evaluate the template compiler without a build. |
||
"@tsconfig/ember": "^2.0.0", | ||
"@types/node": "^18.11.11", | ||
"@types/qunit": "^2.19.4", | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
export default precompileTemplate('', { | ||
moduleName: 'packages/@ember/-internals/glimmer/lib/templates/empty.hbs', | ||
}); | ||
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. I was able to drop all special support for hbs files, and several hacks around their types, by making them just be the equivalent javascript. |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
export default precompileTemplate(`{{component (-outlet)}}`, { | ||
moduleName: 'packages/@ember/-internals/glimmer/lib/templates/outlet.hbs', | ||
}); |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
export default precompileTemplate(`{{component this}}`, { | ||
moduleName: 'packages/@ember/-internals/glimmer/lib/templates/root.hbs', | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// The main entrypoint of ember-template-compiler is the fairly-crufty | ||
// backward-compatible API. In contrast, this is the subset of that that's | ||
// actually used by babel-plugin-ember-template-compilation. | ||
// | ||
// This module exists so that ember-source can build itself -- the | ||
// ember-template-compiler.js bundle it an output of the build, but the build | ||
// needs to compile templates. Unlike the full ./index.ts, this module can be | ||
// directly evaluted in node because it doesn't try to pull in the whole kitchen | ||
// sink. | ||
export { default as precompile } from './lib/system/precompile'; | ||
export { buildCompileOptions as _buildCompileOptions } from './lib/system/compile-options'; | ||
export { preprocess as _preprocess, print as _print } from '@glimmer/syntax'; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// this file gets replaced with the real value during the build | ||
export default 'VERSION_GOES_HERE' as string; |
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 PR makes all the packages real pnpm workspaces, which was necessary to make the ember-template-compiler package actually evaluatable in node. Previously not all packages were. This extra filtering is necessary now that pnpm is creating node_modules directories inside the packages.