Skip to content

Commit

Permalink
move broccoli wrapper into @embroider/compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Jan 21, 2025
1 parent 40aea1c commit 961cea4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
16 changes: 13 additions & 3 deletions packages/compat/src/default-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Variant, EmberAppInstance } from '@embroider/core';
import type { Node } from 'broccoli-node-api';
import writeFile from 'broccoli-file-creator';
import mergeTrees from 'broccoli-merge-trees';
import type Plugin from 'broccoli-plugin';
import Plugin from 'broccoli-plugin';

export interface PipelineOptions<PackagerOptions> extends Options {
packagerOptions?: PackagerOptions;
Expand Down Expand Up @@ -37,10 +37,20 @@ export function prebuild(emberApp: EmberAppInstance, options?: Options): Node {
return mergeTrees([embroiderApp.asStage(addons).tree, writeFile('.stage2-output', () => outputPath)]);
}

export function compatBuild(emberApp: EmberAppInstance, Builder: typeof Plugin, options?: Options): Node {
export function compatBuild(
emberApp: EmberAppInstance,
buildOnce: (outputPath: string, emberEnv: 'development' | 'test' | 'production') => Promise<void>,
options?: Options
): Node {
if (process.env.EMBROIDER_PREBUILD) {
return prebuild(emberApp, options);
}

return new Builder([]);
class Builder extends Plugin {
build(): Promise<void> {
return buildOnce(this.outputPath, emberApp.env);
}
}

return new Builder([], {});
}
2 changes: 1 addition & 1 deletion packages/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export * from './src/assets.js';
export * from './src/content-for.js';
export * from './src/classic-ember-support.js';
export * from './src/ember.js';
export * from './src/broccoli-builder.js';
export * from './src/build-once.js';
1 change: 0 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@embroider/reverse-exports": "workspace:*",
"@rollup/pluginutils": "^5.1.0",
"assert-never": "^1.2.1",
"broccoli-plugin": "^4.0.7",
"browserslist": "*",
"browserslist-to-esbuild": "^2.1.1",
"content-tag": "^2.0.2",
Expand Down
16 changes: 0 additions & 16 deletions packages/vite/src/broccoli-builder.ts

This file was deleted.

16 changes: 16 additions & 0 deletions packages/vite/src/build-once.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { spawn } from 'child_process';

export function buildOnce(outputPath: string, emberEnv: 'development' | 'test' | 'production'): Promise<void> {
return new Promise((resolve, reject) => {
const child = spawn(
`npx vite build --outDir ${outputPath} --mode ${emberEnv === 'production' ? 'production' : 'development'}`,
{
cwd: process.cwd(),
shell: true,
stdio: 'inherit',
env: { ...process.env },
}
);
child.on('exit', code => (code === 0 ? resolve() : reject(new Error('vite build failed'))));
});
}
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/app-template/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { compatBuild } = require('@embroider/compat');

module.exports = async function (defaults) {
const { Builder } = await import('@embroider/vite');
const { buildOnce } = await import('@embroider/vite');
let app = new EmberApp(defaults, {});

return compatBuild(app, Builder);
return compatBuild(app, buildOnce);
};

0 comments on commit 961cea4

Please sign in to comment.