Skip to content

Commit

Permalink
fix script value (#1614)
Browse files Browse the repository at this point in the history
* fix accessing

* adds new function by type

* updates function to remove loop

---------

Co-authored-by: C. J. Tantay <[email protected]>
  • Loading branch information
cjbt and cjtantay authored Nov 7, 2024
1 parent 1e5f4f5 commit 660993e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
12 changes: 9 additions & 3 deletions lib/blocks/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ import debug from 'debug';
import { getStaticPathFromManifestEntry } from './static.js';

const logger = debug('baker:blocks:script');
const EntryTypes = {
CSS: 'css',
MODERN: 'modern',
LEGACY: 'legacy',
};

export function createScriptBlock(rollup) {
return function script(entry, shouldPreload = false) {
const { manifest } = rollup;
const { preloads } = manifest;

const cssEntry = rollup.getManifestEntry(entry);
const modernEntry = rollup.getManifestEntry(entry);
const legacyEntry = rollup.getManifestEntry(entry);
const cssEntry = rollup.getManifestEntryByType(entry, EntryTypes.CSS);
const modernEntry = rollup.getManifestEntryByType(entry, EntryTypes.MODERN);
const legacyEntry = rollup.getManifestEntryByType(entry, EntryTypes.LEGACY);

const output = [];

if (!modernEntry) {
Expand Down
16 changes: 4 additions & 12 deletions lib/engines/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,11 @@ export class BaseEngine {
}

getManifestEntry(key) {
let result = this.manifest[key];

if (!result && this.subManifests.length) {
for (const subManifest of this.subManifests) {
const subResult = this.manifest[subManifest][key];
if (subResult) {
result = subResult;
break;
}
}
}
return this.manifest[key];
}

return result;
getManifestEntryByType(entry, type) {
return this.manifest[type]?.[entry];
}

async outputFile(file) {
Expand Down

0 comments on commit 660993e

Please sign in to comment.