UNPKG

2 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7const path_1 = require("path");
8
9const url = require("url");
10
11const integrity_sha_utils_1 = require("../../../lib/packages/integrity-sha-utils");
12
13function getAssetManifest(assetBasePath, compilation) {
14 return Object.values(compilation.assets).reduce((assets, {
15 existsAt
16 }, index) => {
17 assets.all[index] = path_1.relative(assetBasePath, existsAt);
18 return assets;
19 }, // `all` is a temporary nesting level that mimics the structure expected by `shopify-cloud`.
20 // Eventually, `assets` will just be a flat array.
21 {
22 all: {}
23 });
24}
25
26exports.getAssetManifest = getAssetManifest;
27
28function getAsyncAssetManifest(compilation, {
29 includeIntegrity = true
30} = {}) {
31 const {
32 hashFunction,
33 hashDigest,
34 publicPath
35 } = compilation.outputOptions;
36 const manifest = {};
37
38 for (const chunkGroup of compilation.chunkGroups) {
39 const files = [];
40
41 for (const chunk of chunkGroup.chunks) {
42 for (const file of chunk.files) {
43 if (!file.endsWith('.map')) {
44 const integrity = includeIntegrity && integrity_sha_utils_1.calculateBase64IntegrityFromFilename(file, hashFunction, hashDigest);
45 const fileIntegrity = integrity ? {
46 integrity
47 } : {};
48 files.push(Object.assign({
49 file,
50 publicPath: url.resolve(publicPath || '', file)
51 }, fileIntegrity));
52 }
53 }
54 }
55
56 for (const block of chunkGroup.blocksIterable) {
57 let id = null;
58 const dependency = block.module == null ? null : block.module.dependencies.find(dep => block.request === dep.request);
59
60 if (dependency) {
61 const module = dependency.module;
62 id = module.id;
63 }
64
65 if (id != null) {
66 for (const file of files) {
67 file.id = id;
68 }
69
70 manifest[id] = files;
71 }
72 }
73 }
74
75 return manifest;
76}
77
78exports.getAsyncAssetManifest = getAsyncAssetManifest;
\No newline at end of file