Skip to content

Commit

Permalink
implement broccoli builder for compatPrebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Jan 21, 2025
1 parent 26037ab commit c2a48f9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/compat/src/default-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ export function prebuild(emberApp: EmberAppInstance, options?: Options): Node {

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

export function compatBuild(emberApp: EmberAppInstance, Builder: any, options?: Options): Node {
if (process.env.EMBROIDER_PREBUILD) {
return prebuild(emberApp, options);
}

return new Builder([]);
}
2 changes: 1 addition & 1 deletion packages/compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ 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 { prebuild, PipelineOptions } from './default-pipeline';
export { prebuild, compatBuild, PipelineOptions } from './default-pipeline';
export { PackageRules, ModuleRules } from './dependency-rules';
export type { Options as ResolverTransformOptions } from './resolver-transform';
1 change: 1 addition & 0 deletions packages/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +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';
1 change: 1 addition & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@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: 16 additions & 0 deletions packages/vite/src/broccoli-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Plugin from 'broccoli-plugin';
import { spawn } from 'child_process';

export class Builder extends Plugin {
build(): Promise<void> {
return new Promise((resolve, reject) => {
const child = spawn(`npx vite build --outDir ${this.outputPath}`, {
cwd: process.cwd(),
shell: true,
stdio: 'inherit',
env: { ...process.env, FORCE_BUILD_TESTS: 'true' },
});
child.on('exit', code => (code === 0 ? resolve() : reject(new Error('vite build failed'))));
});
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

7 changes: 4 additions & 3 deletions tests/app-template/ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

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

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

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

0 comments on commit c2a48f9

Please sign in to comment.