Skip to content

Commit

Permalink
fix internals
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Dec 7, 2023
1 parent 6fb8783 commit ee7f862
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
6 changes: 4 additions & 2 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ export class CompatAppBuilder {
}
}

for (let asset of this.emberEntrypoints(treePaths.htmlTree)) {
assets.push(asset);
if (treePaths.htmlTree) {
for (let asset of this.emberEntrypoints(treePaths.htmlTree)) {
assets.push(asset);
}
}

return assets;
Expand Down
12 changes: 11 additions & 1 deletion packages/vite/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ export function assets(options?: { entryDirectories?: string[] }): Plugin {
}
return readFileSync(rewrittenApp + id.replace(root + '/assets/', '/assets/').split('?')[0]).toString();
}
}
},
async writeBundle(options) {
const { compatAppBuilder } = getCompatAppBuilder({
rewrittenPackageCache: resolverLoader.resolver.packageCache,
root: options.dir || join(cwd, 'dist')
});
const assets = compatAppBuilder['gatherAssets']({
publicTree: 'public',
} as any)
await compatAppBuilder['updateAssets'](assets, [], {});
},
}
}
20 changes: 2 additions & 18 deletions packages/vite/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { join, dirname } from 'path';
import { join } from 'path';
import { createHash } from 'crypto';
import { fork } from 'child_process';
import { ResolverLoader } from '@embroider/core';
import { existsSync, readdirSync, readFileSync, writeFileSync, copyFileSync } from 'fs';
import { mkdirpSync } from 'fs-extra';
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import { Plugin } from 'vite';

const cwd = process.cwd();
Expand Down Expand Up @@ -60,8 +58,6 @@ export async function buildIfFileChanged(path: string | null | undefined): Promi
}

export function build(): Plugin {
let resolverLoader = new ResolverLoader(process.cwd());
const engine = resolverLoader.resolver.options.engines[0];
return {
name: 'embroider-builder',
enforce: 'pre',
Expand All @@ -79,18 +75,6 @@ export function build(): Plugin {
}
});
},
writeBundle(options) {
engine.activeAddons.forEach(addon => {
const pkg = resolverLoader.resolver.packageCache.ownerOfFile(addon.root);
if (!pkg) return;
if (!pkg?.isV2Addon()) return;
const assets = pkg.meta['public-assets'] || {};
Object.entries(assets).forEach(([path, dest]) => {
mkdirpSync(dirname(join(options.dir!, dest)));
copyFileSync(join(pkg.root, path), join(options.dir!, dest));
});
});
},
async buildStart() {
if (!existsSync(embroiderDir)) {
await emberBuild();
Expand Down
2 changes: 1 addition & 1 deletion tests/vite-app/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default defineConfig({
build: {
rollupOptions: {
input: {
main: resolve(root, "index.html"),
main: resolve('.', "index.html"),
tests: resolve(".", "tests/index.html"),
},
},
Expand Down

0 comments on commit ee7f862

Please sign in to comment.