Skip to content
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

Streamline template compilation, part 2 #1276

Merged
merged 31 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b4a8005
pruning out unused feature from inilne-deps-plugin
ef4 Nov 7, 2022
05128b4
switch stage3 to direct use of babel-plugin-ember-template-compilation
ef4 Nov 7, 2022
f87ec9b
beginning to re-integrate resolution within templates
ef4 Nov 8, 2022
3c8e831
got the basic cases working
ef4 Nov 9, 2022
98b6732
reording for ease of reading
ef4 Nov 9, 2022
c185c39
working through the resolver tests
ef4 Nov 9, 2022
02faaca
porting more resolver test cases
ef4 Nov 10, 2022
db6dc42
Merge branch 'main' into e-template-compilation-refactor
ef4 Nov 10, 2022
2142c01
more progress through resolver tests
ef4 Nov 10, 2022
768fc06
more progress through resolver tests
ef4 Nov 10, 2022
a32a650
more progress on resolver tests
ef4 Nov 10, 2022
15b4ca0
update static-app now that components are not in amd loader
ef4 Nov 10, 2022
fbf60dd
refactor away unused method
ef4 Nov 10, 2022
3dd9ca2
dropping old template compiler implementation
ef4 Nov 10, 2022
fa046e9
prune more of the old implementation
ef4 Nov 10, 2022
ac42e9b
pruning more unused things
ef4 Nov 10, 2022
20f6df2
Merge branch 'main' into e-template-compilation-refactor
ef4 Nov 15, 2022
a48130d
remove misleading comment
ef4 Nov 15, 2022
40ae3e2
remove dead function
ef4 Nov 15, 2022
35ea56c
support moduleName backward compatibility
ef4 Nov 15, 2022
5a26466
needs to be a dep, not a devDep
ef4 Nov 16, 2022
83a17e3
workaround for ember helper invocation bug
ef4 Nov 16, 2022
41c6a4c
Merge branch 'main' into e-template-compilation-refactor
ef4 Nov 16, 2022
0e23724
one case wasn't obeying the new patchHelpersBug
ef4 Nov 16, 2022
0512e66
adjust static helper test
ef4 Nov 16, 2022
438d77f
Update vendored ember-template-compiler
ef4 Nov 16, 2022
5561413
update to babel-plugin-ember-template-compilation alpha.4
ef4 Nov 16, 2022
bb05e62
we don't need to repeat this scenario for all ember versions
ef4 Nov 16, 2022
e9af2cc
normalize path separators when using backward-compatible moduleName
ef4 Nov 17, 2022
6a21a43
eliminate unneeded core/resolver interface
ef4 Nov 17, 2022
00ca884
bump to released version of babel-plugin-ember-template-compilation
ef4 Nov 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
eqeqeq: ['error', 'smart'],
'no-debugger': 'error',
'no-new-wrappers': 'error',
'no-redeclare': 'error',
'no-unused-labels': 'error',
'no-var': 'error',

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
supports source-to-source transformation (and it offers new capabilities to
AST transform authors that we would like to be available everywhere).

## `@embroider/shared-internals`

- BREAKING: options format of `hbsToJS` changed

# Release 2022-10-06.0

## `@embroider/core` 1.8.3 -> 1.9.0 minor
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"tests/v2-addon-template"
],
"nohoist": [
"**/@types/broccoli-plugin"
"**/@types/broccoli-plugin",
"**/babel-plugin-ember-template-compilation"
]
},
"scripts": {
Expand Down
6 changes: 0 additions & 6 deletions packages/babel-loader-8/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,3 @@ module.exports = require('babel-loader').custom(babel => {
},
};
});

function pluginMatches(pattern) {
return function (plugin) {
return plugin && pattern.test(Array.isArray(plugin) ? plugin[0] : plugin);
};
}
5 changes: 3 additions & 2 deletions packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@types/babel__code-frame": "^7.0.2",
"@types/yargs": "^17.0.3",
"assert-never": "^1.1.0",
"babel-plugin-ember-template-compilation": "^2.0.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babylon": "^6.18.0",
"bind-decorator": "^1.0.11",
Expand Down Expand Up @@ -64,7 +65,7 @@
"devDependencies": {
"@embroider/sample-transforms": "0.0.0",
"@embroider/test-support": "0.36.0",
"@glimmer/syntax": "0.80.0",
"@glimmer/syntax": "^0.84.2",
"@types/babel__core": "^7.1.14",
"@types/babel__generator": "^7.6.2",
"@types/babel__template": "^7.4.0",
Expand All @@ -77,7 +78,7 @@
"@types/node": "^15.12.2",
"@types/resolve": "^1.20.0",
"@types/semver": "^7.3.6",
"@types/strip-bom": "^4.0.1",
"code-equality-assertions": "^0.7.0",
"ember-cli-htmlbars-3": "npm:ember-cli-htmlbars@3",
"ember-cli-htmlbars-inline-precompile": "^2.1.0",
"ember-engines": "^0.8.19",
Expand Down
30 changes: 7 additions & 23 deletions packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import {
AppBuilder,
EmberENV,
Package,
TemplateCompilerPlugins,
Resolver,
NodeTemplateCompiler,
AddonPackage,
} from '@embroider/core';
import V1InstanceCache from './v1-instance-cache';
Expand All @@ -35,7 +32,7 @@ import bind from 'bind-decorator';
import { pathExistsSync } from 'fs-extra';
import { tmpdir } from '@embroider/shared-internals';
import { Options as AdjustImportsOptions } from '@embroider/core/src/babel-plugin-adjust-imports';
import { getEmberExports } from '@embroider/core/src/load-ember-template-compiler';
import type { Transform } from 'babel-plugin-ember-template-compilation';

interface TreeNames {
appJS: BroccoliNode;
Expand Down Expand Up @@ -325,15 +322,16 @@ class CompatAppAdapter implements AppAdapter<TreeNames> {
}

@Memoize()
templateResolver(): Resolver {
resolverTransform(): Transform | undefined {
return new CompatResolver({
emberVersion: this.activeAddonChildren().find(a => a.name === 'ember-source')!.packageJSON.version,
root: this.root,
modulePrefix: this.modulePrefix(),
podModulePrefix: this.podModulePrefix(),
options: this.options,
activePackageRules: this.activeRules(),
adjustImportsOptionsPath: this.adjustImportsOptionsPath(),
});
}).astTransformer();
}

@Memoize()
Expand Down Expand Up @@ -382,28 +380,14 @@ class CompatAppAdapter implements AppAdapter<TreeNames> {
// rules.
@Memoize()
private internalTemplateResolver(): CompatResolver {
let resolver = new CompatResolver({
return new CompatResolver({
emberVersion: this.activeAddonChildren().find(a => a.name === 'ember-source')!.packageJSON.version,
root: this.root,
modulePrefix: this.modulePrefix(),
options: this.options,
activePackageRules: this.activeRules(),
adjustImportsOptions: this.makeAdjustImportOptions(false),
});

const compilerPath = resolveSync(this.templateCompilerPath(), { basedir: this.root });
const { cacheKey: compilerChecksum } = getEmberExports(compilerPath);
// It's ok that this isn't a fully configured template compiler. We're only
// using it to parse component snippets out of rules.
resolver.astTransformer(
new NodeTemplateCompiler({
compilerPath,
compilerChecksum,

EmberENV: {},
plugins: {},
})
);
return resolver;
}

private extraImports() {
Expand All @@ -428,7 +412,7 @@ class CompatAppAdapter implements AppAdapter<TreeNames> {
return flatten(output);
}

htmlbarsPlugins(): TemplateCompilerPlugins {
htmlbarsPlugins(): Transform[] {
return this.oldPackage.htmlbarsPlugins;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/compat/src/dasherize-component-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export function dasherize(key: string) {

return name;
}

const NAME_FROM_SNIPPET = /<(?:([^\s/]+).*>)|(?:{{\s?component\s+['"]([^'"]+)['"])|(?:\{\{([^\s]+).*\}\})/;
export function snippetToDasherizedName(snippet: string): string | undefined {
let result = NAME_FROM_SNIPPET.exec(snippet);
if (result) {
return dasherize(result[1] ?? result[2] ?? result[3]);
}
}
7 changes: 6 additions & 1 deletion packages/compat/src/dependency-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ export function expandModuleRules(absPath: string, moduleRules: ModuleRules, res
if (moduleRules.dependsOnComponents) {
for (let snippet of moduleRules.dependsOnComponents) {
let found = resolver.resolveComponentSnippet(snippet, moduleRules);
for (let { absPath: target, runtimeName } of found.modules) {
if (found.jsModule) {
let { absPath: target, runtimeName } = found.jsModule;
output.push({ absPath, target: explicitRelative(dirname(absPath), target), runtimeName });
}
if (found.hbsModule) {
let { absPath: target, runtimeName } = found.hbsModule;
output.push({ absPath, target: explicitRelative(dirname(absPath), target), runtimeName });
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/hbs-to-js-broccoli-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class TemplateCompileTree extends Filter {
}

processString(source: string, relativePath: string) {
return hbsToJS(source, relativePath);
return hbsToJS(source, { filename: relativePath });
}
baseDir() {
return join(__dirname, '..');
Expand Down
Loading