"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var extractChunks_exports = {};
__export(extractChunks_exports, {
  extractChunks: () => extractChunks
});
module.exports = __toCommonJS(extractChunks_exports);
/**
 * @license
 * Copyright 2018 Google Inc.
 * https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/extract-chunks.js
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function isAsync(chunk) {
  if ("canBeInitial" in chunk) {
    return !chunk.canBeInitial();
  } else if ("isInitial" in chunk) {
    return !chunk.isInitial();
  }
  return !chunk.initial;
}
function extractChunks({
  compilation,
  includeType
}) {
  const chunks = [...compilation.chunks];
  if (includeType === void 0 || includeType === "async-chunks") {
    return chunks.filter(isAsync);
  }
  if (includeType === "initial") {
    return chunks.filter((chunk) => !isAsync(chunk));
  }
  if (includeType === "all-chunks") {
    return chunks;
  }
  if (includeType === "all-assets") {
    const licenseAssets = [...compilation.assetsInfo.values()].map((info) => {
      var _a;
      if ((_a = info.related) == null ? void 0 : _a.license) {
        return info.related.license;
      }
      return false;
    }).filter(Boolean);
    return [
      {
        // @ts-expect-error ignore ts check for files
        files: Object.keys(compilation.assets).filter(
          (t) => !licenseAssets.includes(t)
        )
      }
    ];
  }
  return chunks;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  extractChunks
});
