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

Add a new prebuild function with strict defaults #1819

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 27 additions & 2 deletions packages/compat/src/default-pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Options } from '.';
import type Options from './options';
import { recommendedOptions } from './options';
import { App, Addons as CompatAddons } from '.';
import type { PackagerConstructor, Variant, EmberAppInstance } from '@embroider/core';
import { toBroccoliPlugin } from '@embroider/core';
Expand All @@ -12,7 +13,6 @@ import { sync as pkgUpSync } from 'pkg-up';

export interface PipelineOptions<PackagerOptions> extends Options {
packagerOptions?: PackagerOptions;
onOutputPath?: (outputPath: string) => void;
variants?: Variant[];
}

Expand Down Expand Up @@ -51,6 +51,31 @@ export default function defaultPipeline<PackagerOptions>(
return new BroccoliPackager(embroiderApp.asStage(addons), variants, options && options.packagerOptions);
}

const defaultPrebuildOptions = {
...recommendedOptions.optimized,
amdCompatibility: {
es: [],
},
};

export function prebuild(emberApp: EmberAppInstance, options: Options = defaultPrebuildOptions): Node {
let outputPath: string;
let addons;

let embroiderApp = new App(emberApp, options);

addons = new CompatAddons(embroiderApp);
addons.ready().then(result => {
outputPath = result.outputPath;
});

if (process.env.STAGE1_ONLY) {
return mergeTrees([addons.tree, writeFile('.stage1-output', () => outputPath)]);
}

return mergeTrees([embroiderApp.asStage(addons).tree, writeFile('.stage2-output', () => outputPath)]);
}

function hasFastboot(emberApp: EmberAppInstance | EmberAppInstance) {
return emberApp.project.addons.find(a => a.name === 'ember-cli-fastboot');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export { default as App } from './compat-app';
export { default as Addons } from './compat-addons';
export { default as Options, recommendedOptions } from './options';
export { default as V1Addon } from './v1-addon';
export { default as compatBuild, PipelineOptions } from './default-pipeline';
export { default as compatBuild, prebuild, PipelineOptions } from './default-pipeline';
export { PackageRules, ModuleRules } from './dependency-rules';
14 changes: 2 additions & 12 deletions tests/vite-app/ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { compatBuild } = require('@embroider/compat');
const { prebuild } = require('@embroider/compat');

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
// Add options here
});

return compatBuild(app, undefined, {
staticAddonTrees: true,
staticAddonTestSupportTrees: true,
staticComponents: true,
staticHelpers: true,
staticModifiers: true,
staticEmberSource: true,
amdCompatibility: {
es: [],
},
});
return prebuild(app);
};
Loading