diff --git a/packages/compat/src/default-pipeline.ts b/packages/compat/src/default-pipeline.ts index 13b28d225..e8374a7f8 100644 --- a/packages/compat/src/default-pipeline.ts +++ b/packages/compat/src/default-pipeline.ts @@ -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'; @@ -12,7 +13,6 @@ import { sync as pkgUpSync } from 'pkg-up'; export interface PipelineOptions extends Options { packagerOptions?: PackagerOptions; - onOutputPath?: (outputPath: string) => void; variants?: Variant[]; } @@ -51,6 +51,31 @@ export default function defaultPipeline( 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'); } diff --git a/packages/compat/src/index.ts b/packages/compat/src/index.ts index 3383f6f93..313e45051 100644 --- a/packages/compat/src/index.ts +++ b/packages/compat/src/index.ts @@ -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'; diff --git a/tests/vite-app/ember-cli-build.js b/tests/vite-app/ember-cli-build.js index 53524b0d4..9b9de5318 100644 --- a/tests/vite-app/ember-cli-build.js +++ b/tests/vite-app/ember-cli-build.js @@ -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); };