"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cli_core_1 = require("@bluebase/cli-core");
const fromRoot_1 = __importDefault(require("../../scripts/fromRoot"));
// import fs from 'fs';
const webpack_merge_1 = __importDefault(require("webpack-merge"));
const webpack_node_externals_1 = __importDefault(require("webpack-node-externals"));
const removeNil = cli_core_1.Utils.removeNil;
/**
 * We don't want our node_modules to be bundled with any bundle that is
 * targetting the node environment, prefering them to be resolved via
 * native node module system. Therefore we use the `webpack-node-externals`
 * library to help us generate an externals configuration that will
 * ignore all the node_modules.
 * @param config
 * @param builder
 */
const NodeExternals = (options = {}) => (config, builder) => {
    return webpack_merge_1.default(config, {
        externals: [
            webpack_node_externals_1.default(Object.assign({ 
                // Modules dir
                modulesDir: fromRoot_1.default('./node_modules'), whitelist: removeNil([
                    // We always want the source-map-support included in
                    // our node target bundles.
                    'source-map-support/register',
                ])
                    // And any items that have been whitelisted in the config need
                    // to be included in the bundling process too.
                    .concat(builder.configs.nodeExternalsFileTypeWhitelist || []) }, options)),
        ],
    });
};
// function getMyDependencies() {
// 	const pkgJsonPath = fromRoot('package.json');
// 	const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath).toString());
// 	return Object.keys(pkgJson.dependencies);
// }
exports.default = NodeExternals;
//# sourceMappingURL=NodeExternals.js.map