Skip to content

Commit

Permalink
Merge branch 'main' into improve-addon-clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 authored Sep 3, 2024
2 parents 1467bde + e1733ef commit 41f2cd6
Show file tree
Hide file tree
Showing 45 changed files with 328 additions and 372 deletions.
1 change: 1 addition & 0 deletions packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"lodash": "^4.17.21",
"pkg-up": "^3.1.0",
"resolve": "^1.20.0",
"resolve.exports": "^2.0.2",
"resolve-package-path": "^4.0.1",
"semver": "^7.3.5",
"symlink-or-copy": "^1.3.1",
Expand Down
19 changes: 11 additions & 8 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,10 @@ export class CompatAppBuilder {
return ['.wasm', '.mjs', '.js', '.json', '.ts', '.hbs', '.hbs.js', '.gjs', '.gts'];
}

private addEmberEntrypoints(htmlTreePath: string): string[] {
let classicEntrypoints = ['index.html', 'tests/index.html'];
if (!this.compatApp.shouldBuildTests) {
classicEntrypoints.pop();
}
private addEmberEntrypoints(): string[] {
let classicEntrypoints = ['index.html'];
for (let entrypoint of classicEntrypoints) {
let sourcePath = join(htmlTreePath, entrypoint);
let sourcePath = join(this.compatApp.root, entrypoint);
let rewrittenAppPath = join(this.root, entrypoint);
writeFileSync(rewrittenAppPath, readFileSync(sourcePath));
}
Expand Down Expand Up @@ -463,7 +460,7 @@ export class CompatAppBuilder {
}

let appFiles = this.updateAppJS(inputPaths.appJS);
let assetPaths = this.addEmberEntrypoints(inputPaths.htmlTree);
let assetPaths = this.addEmberEntrypoints();

if (this.activeFastboot) {
// when using fastboot, our own package.json needs to be in the output so fastboot can read it.
Expand Down Expand Up @@ -509,6 +506,13 @@ export class CompatAppBuilder {

if ((this.origAppPackage.packageJSON['ember-addon']?.version ?? 0) < 2) {
meta['auto-upgraded'] = true;
// our rewriting keeps app in app directory, etc.
pkgLayers.push({
exports: {
'./*': './app/*',
'./tests/*': './tests/*',
},
});
}

pkgLayers.push({ 'ember-addon': meta });
Expand Down Expand Up @@ -734,7 +738,6 @@ function addCachablePlugin(babelConfig: TransformOptions) {

interface TreeNames {
appJS: BroccoliNode;
htmlTree: BroccoliNode;
publicTree: BroccoliNode | undefined;
configTree: BroccoliNode;
}
45 changes: 1 addition & 44 deletions packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ export default class CompatApp {
return require(resolve.sync(specifier, { basedir: this.emberCLILocation }));
}

private get configReplace() {
return this.requireFromEmberCLI('broccoli-config-replace');
}

private get configLoader() {
return this.requireFromEmberCLI('broccoli-config-loader');
}
Expand Down Expand Up @@ -184,45 +180,6 @@ export default class CompatApp {
};
}

private get htmlTree() {
if (this.legacyEmberAppInstance.tests) {
return mergeTrees([this.indexTree, this.testIndexTree]);
} else {
return this.indexTree;
}
}

private get indexTree() {
let indexFilePath = this.legacyEmberAppInstance.options.outputPaths.app.html;
let index = buildFunnel(this.legacyEmberAppInstance.trees.app, {
allowEmpty: true,
include: [`index.html`],
getDestinationPath: () => indexFilePath,
annotation: 'app/index.html',
});
return new this.configReplace(index, this.configTree, {
configPath: join('environments', `${this.legacyEmberAppInstance.env}.json`),
files: [indexFilePath],
patterns: this.filteredPatternsByContentFor.others,
annotation: 'ConfigReplace/indexTree',
});
}

private get testIndexTree() {
let index = buildFunnel(this.legacyEmberAppInstance.trees.tests, {
allowEmpty: true,
include: [`index.html`],
destDir: 'tests',
annotation: 'tests/index.html',
});
return new this.configReplace(index, this.configTree, {
configPath: join('environments', `test.json`),
files: ['tests/index.html'],
patterns: this.filteredPatternsByContentFor.others,
annotation: 'ConfigReplace/testIndexTree',
});
}

@Memoize()
babelConfig(): TransformOptions {
// this finds all the built-in babel configuration that comes with ember-cli-babel
Expand Down Expand Up @@ -618,6 +575,7 @@ export default class CompatApp {
return this.preprocessJS(
buildFunnel(this.legacyEmberAppInstance.trees.app, {
exclude: ['styles/**', '*.html'],
destDir: 'app',
})
);
}
Expand Down Expand Up @@ -726,7 +684,6 @@ export default class CompatApp {

return {
appJS: this.processAppJS().appJS,
htmlTree: this.htmlTree,
publicTree,
configTree,
contentForTree,
Expand Down
27 changes: 17 additions & 10 deletions packages/compat/src/dependency-rules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Resolver } from '@embroider/core';
import { getOrCreate } from '@embroider/core';
import { resolve } from 'path';
import { resolve as pathResolve, dirname } from 'path';
import { satisfies } from 'semver';
import { resolve as resolveExports } from 'resolve.exports';

export interface PackageRules {
// This whole set of rules will only apply when the given addon package
Expand Down Expand Up @@ -232,14 +233,20 @@ export function activePackageRules(

export function appTreeRulesDir(root: string, resolver: Resolver) {
let pkg = resolver.packageCache.ownerOfFile(root);
if (pkg?.isV2Addon()) {
// in general v2 addons can keep their app tree stuff in other places than
// "_app_" and we would need to check their package.json to see. But this code
// is only for applying packageRules to auto-upgraded v1 addons and apps, and
// those we always organize predictably.
return resolve(root, '_app_');
} else {
// auto-upgraded apps don't get an exist _app_ dir.
return root;
if (pkg) {
if (pkg.isV2Addon()) {
// in general v2 addons can keep their app tree stuff in other places than
// "_app_" and we would need to check their package.json to see. But this code
// is only for applying packageRules to auto-upgraded v1 addons and apps, and
// those we always organize predictably.
return pathResolve(root, '_app_');
} else {
// this is an app
let matched = resolveExports(pkg.packageJSON, './index.js');
if (matched) {
return dirname(pathResolve(root, matched[0]));
}
}
}
return root;
}
14 changes: 7 additions & 7 deletions packages/compat/src/resolver-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,17 +547,17 @@ class TemplateResolver implements ASTPlugin {
2. Have a mustache statement like: `{{something}}`, where `something` is:
a. Not a variable in scope (for example, there's no preceeding line
a. Not a variable in scope (for example, there's no preceeding line
like `<Parent as |something|>`)
b. Does not start with `@` because that must be an argument from outside this template.
c. Does not contain a dot, like `some.thing` (because that case is classically
c. Does not contain a dot, like `some.thing` (because that case is classically
never a global component resolution that we would need to handle)
d. Does not start with `this` (this rule is mostly redundant with the previous rule,
d. Does not start with `this` (this rule is mostly redundant with the previous rule,
but even a standalone `this` is never a component invocation).
e. Does not have any arguments. If there are argument like `{{something a=b}}`,
there is still ambiguity between helper vs component, but there is no longer
e. Does not have any arguments. If there are argument like `{{something a=b}}`,
there is still ambiguity between helper vs component, but there is no longer
the possibility that this was just rendering some data.
f. Does not take a block, like `{{#something}}{{/something}}` (because that is
f. Does not take a block, like `{{#something}}{{/something}}` (because that is
always a component, no ambiguity.)
We can't tell if this problematic case is really:
Expand All @@ -571,7 +571,7 @@ class TemplateResolver implements ASTPlugin {
2. A component invocation, which you could have written `<Something />`
instead. Angle-bracket invocation has been available and easy-to-adopt
for a very long time.
for a very long time.
3. Property-this-fallback for `{{this.something}}`. Property-this-fallback
is eliminated at Ember 4.0, so people have been heavily pushed to get
Expand Down
4 changes: 4 additions & 0 deletions packages/compat/tests/audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ describe('audit', function () {
merge(app.pkg, {
'ember-addon': appMeta,
keywords: ['ember-addon'],
exports: {
'./*': './*',
'./tests/*': './tests/*',
},
});
});

Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/app-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface RouteFiles {
}

export class AppFiles {
readonly tests: ReadonlyArray<string>;
readonly components: ReadonlyArray<string>;
readonly helpers: ReadonlyArray<string>;
readonly modifiers: ReadonlyArray<string>;
Expand All @@ -26,7 +25,6 @@ export class AppFiles {
staticAppPathsPattern: RegExp | undefined,
podModulePrefix?: string
) {
let tests: string[] = [];
let components: string[] = [];
let helpers: string[] = [];
let modifiers: string[] = [];
Expand Down Expand Up @@ -78,7 +76,7 @@ export class AppFiles {
}

if (relativePath.startsWith('tests/')) {
tests.push(relativePath);
// skip tests because they are dealt with separately
continue;
}

Expand Down Expand Up @@ -134,7 +132,6 @@ export class AppFiles {
otherAppFiles.push(relativePath);
}
}
this.tests = tests;
this.components = components;
this.helpers = helpers;
this.modifiers = modifiers;
Expand Down
Loading

0 comments on commit 41f2cd6

Please sign in to comment.