Skip to content

Commit

Permalink
Merge pull request #2223 from embroider-build/remove-app-meta
Browse files Browse the repository at this point in the history
Remove app meta
  • Loading branch information
ef4 authored Jan 3, 2025
2 parents d367b87 + 1aed0c3 commit c3af848
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 383 deletions.
2 changes: 1 addition & 1 deletion packages/addon-shim/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ShimOptions {

function addonMeta(pkgJSON: PackageInfo): AddonMeta {
let meta = pkgJSON['ember-addon'];
if (meta?.version !== 2 || meta?.type !== 'addon') {
if (meta?.version !== 2) {
throw new Error(`did not find valid v2 addon metadata in ${pkgJSON.name}`);
}
return meta as AddonMeta;
Expand Down
7 changes: 1 addition & 6 deletions packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"src/**/*.d.ts",
"src/**/*.js.map"
],
"bin": {
"embroider-compat-audit": "./src/audit-cli.js"
},
"scripts": {
"test": "jest"
},
Expand All @@ -35,7 +32,6 @@
"@babel/traverse": "^7.14.5",
"@embroider/macros": "workspace:*",
"@types/babel__code-frame": "^7.0.2",
"@types/yargs": "^17.0.3",
"assert-never": "^1.1.0",
"babel-import-util": "^2.0.0",
"babel-plugin-debug-macros": "^1.0.2",
Expand Down Expand Up @@ -67,8 +63,7 @@
"symlink-or-copy": "^1.3.1",
"tree-sync": "^2.1.0",
"typescript-memoize": "^1.0.1",
"walk-sync": "^3.0.0",
"yargs": "^17.0.1"
"walk-sync": "^3.0.0"
},
"devDependencies": {
"@embroider/core": "workspace:^",
Expand Down
173 changes: 0 additions & 173 deletions packages/compat/src/audit-cli.ts

This file was deleted.

28 changes: 7 additions & 21 deletions packages/compat/src/audit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync, readJSONSync } from 'fs-extra';
import { join, resolve as resolvePath, dirname } from 'path';
import type { AppMeta, ResolverOptions } from '@embroider/core';
import type { ResolverOptions } from '@embroider/core';
import { explicitRelative, hbsToJS, locateEmbroiderWorkingDir, Resolver, RewrittenPackageCache } from '@embroider/core';
import { Memoize } from 'typescript-memoize';
import chalk from 'chalk';
Expand Down Expand Up @@ -125,23 +125,14 @@ export class Audit {
return audit.run();
}

constructor(private originAppRoot: string, private options: AuditOptions = {}) {}

@Memoize()
private get pkg() {
return readJSONSync(join(this.movedAppRoot, 'package.json'));
}
constructor(private originAppRoot: string, private options: AuditOptions) {}

@Memoize()
private get movedAppRoot() {
let cache = RewrittenPackageCache.shared('embroider', this.originAppRoot);
return cache.maybeMoved(cache.get(this.originAppRoot)).root;
}

private get meta() {
return this.pkg['ember-addon'] as AppMeta;
}

@Memoize()
private get babelConfig() {
let origCwd = process.cwd();
Expand All @@ -166,18 +157,13 @@ export class Audit {

private resolver = new Resolver(this.resolverParams);

private debug(message: string, ...args: any[]) {
if (this.options.debug) {
console.log(message, ...args);
}
}

async run(): Promise<AuditResults> {
(globalThis as any).embroider_audit = this.handleResolverError.bind(this);

try {
this.debug(`meta`, this.meta);
let entrypoints = this.meta.assets.filter(a => a.endsWith('html')).map(a => resolvePath(this.movedAppRoot, a));
let entrypoints = this.options.entrypoints
.filter(a => a.endsWith('html'))
.map(a => resolvePath(this.movedAppRoot, a));

let modules = await visitModules({
base: this.originAppRoot,
Expand All @@ -204,11 +190,11 @@ export class Audit {
return undefined;
}

if (fromFile.endsWith('.html') && specifier.startsWith(this.meta['root-url'])) {
if (fromFile.endsWith('.html') && specifier.startsWith(this.options.rootURL)) {
// root-relative URLs in HTML are actually relative to the appDir
specifier = explicitRelative(
dirname(fromFile),
resolvePath(this.movedAppRoot, specifier.replace(this.meta['root-url'], ''))
resolvePath(this.movedAppRoot, specifier.replace(this.options.rootURL, ''))
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/compat/src/audit/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface AuditOptions {
debug?: boolean;
entrypoints: string[];
rootURL: string;
}

export interface AuditBuildOptions extends AuditOptions {
Expand Down
1 change: 0 additions & 1 deletion packages/compat/src/compat-adapters/ember-cli-fastboot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class RewriteManifest extends Plugin {
// treated as ember code it needs to have v2 addon metadata
json.keywords = [...(json.keywords ?? []), 'ember-addon'];
let meta: AddonMeta = {
type: 'addon',
version: 2,
'auto-upgraded': true,
};
Expand Down
1 change: 0 additions & 1 deletion packages/compat/src/compat-adapters/ember-cli-mirage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default class extends V1Addon {
return super.packageMeta;
}
return {
type: 'addon',
version: 2,
'auto-upgraded': true,
};
Expand Down
2 changes: 0 additions & 2 deletions packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ export default class CompatApp {
let remapAsset = this.remapAsset.bind(this);

let addonMeta: AddonMeta = {
type: 'addon',
version: 2,
'implicit-scripts': this._implicitScripts.map(remapAsset).filter(forbiddenVendorPath),
'implicit-styles': this._implicitStyles.map(remapAsset),
Expand Down Expand Up @@ -469,7 +468,6 @@ export default class CompatApp {

return new AddToTree(styles, outputPath => {
let addonMeta: AddonMeta = {
type: 'addon',
version: 2,
'public-assets': {},
};
Expand Down
15 changes: 4 additions & 11 deletions packages/compat/tests/audit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { emberTemplateCompiler } from '@embroider/test-support';
import { Project } from 'scenario-tester';
import type { AppMeta } from '@embroider/core';
import { throwOnWarnings } from '@embroider/core';
import merge from 'lodash/merge';
import fromPairs from 'lodash/fromPairs';
Expand All @@ -22,7 +21,10 @@ describe('audit', function () {
let origCwd = process.cwd();
try {
process.chdir(app.baseDir);
let audit = new Audit(app.baseDir);
let audit = new Audit(app.baseDir, {
entrypoints: ['index.html'],
rootURL: '/',
});
return await audit.run();
} finally {
process.chdir(origCwd);
Expand Down Expand Up @@ -124,16 +126,7 @@ describe('audit', function () {
},
},
});
let appMeta: AppMeta = {
type: 'app',
version: 2,
assets: ['index.html'],
'root-url': '/',
'auto-upgraded': true,
};
merge(app.pkg, {
'ember-addon': appMeta,
keywords: ['ember-addon'],
exports: {
'./*': './*',
'./tests/*': './tests/*',
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
export {
Packager,
PackagerConstructor,
Variant,
applyVariantToBabelConfig,
getAppMeta,
getPackagerCacheDir,
} from './packager';
export { Packager, PackagerConstructor, Variant, applyVariantToBabelConfig, getPackagerCacheDir } from './packager';
export { HTMLEntrypoint, BundleSummary } from './html-entrypoint';
export { default as Stage } from './stage';
export { default as Options, optionsWithDefaults } from './options';
Expand Down
Loading

0 comments on commit c3af848

Please sign in to comment.