Skip to content

Commit

Permalink
feat(app/addons public-assets): re-add the blocks that creates assets…
Browse files Browse the repository at this point in the history
… on disk so they can be used in build mode
  • Loading branch information
BlueCutOfficial committed Mar 12, 2024
1 parent e8cacb2 commit 705ffd4
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Resolver,
locateEmbroiderWorkingDir,
} from '@embroider/core';
import walkSync from 'walk-sync';
import { resolve as resolvePath, posix } from 'path';
import type { JSDOM } from 'jsdom';
import type Options from './options';
Expand Down Expand Up @@ -89,6 +90,29 @@ export class CompatAppBuilder {
private extractAssets(treePaths: OutputPaths<TreeNames>): Asset[] {
let assets: Asset[] = [];

// Everything in our traditional public tree is an on-disk asset
// In dev mode, Vite middleware can return the public assets, but
// in build mode, they still need to be copied from rewritten app
// to dist
const isBuildMode = false; // TODO: how to know?
if (isBuildMode) {
if (treePaths.publicTree) {
walkSync
.entries(treePaths.publicTree, {
directories: false,
})
.forEach(entry => {
assets.push({
kind: 'on-disk',
relativePath: entry.relativePath,
sourcePath: entry.fullPath,
mtime: entry.mtime as unknown as number, // https://github.com/joliss/node-walk-sync/pull/38
size: entry.size,
});
});
}
}

// ember-cli traditionally outputs a dummy testem.js file to prevent
// spurious errors when running tests under "ember s".
if (this.compatApp.shouldBuildTests) {
Expand Down Expand Up @@ -886,6 +910,28 @@ export class CompatAppBuilder {
// first gather all the assets out of addons
let assets: Asset[] = [];

// In dev mode, Vite middleware can return the public assets, but
// in build mode, they still need to be copied from rewritten app
// to dist
const isBuildMode = false; // TODO: how to know?
if (isBuildMode) {
for (let pkg of this.allActiveAddons) {
if (pkg.meta['public-assets']) {
for (let [filename, appRelativeURL] of Object.entries(pkg.meta['public-assets'] || {})) {
let sourcePath = resolvePath(pkg.root, filename);
let stats = statSync(sourcePath);
assets.push({
kind: 'on-disk',
sourcePath,
relativePath: appRelativeURL,
mtime: stats.mtimeMs,
size: stats.size,
});
}
}
}
}

if (this.activeFastboot) {
const source = `
(function(){
Expand Down

0 comments on commit 705ffd4

Please sign in to comment.