Skip to content

Commit

Permalink
Merge pull request #1819 from BlueCutOfficial/compat-prebuild-function
Browse files Browse the repository at this point in the history
Add a new prebuild function with strict defaults
  • Loading branch information
mansona authored Feb 29, 2024
2 parents c52ad5c + e6d744e commit a90d03d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
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);
};

0 comments on commit a90d03d

Please sign in to comment.