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AS,CAC1B,WACA,QACA,UACA,YACA,MAA2B,QAApB,EAAO,SAAqB,KAAO,IAC1C,OAAQ,EACR,WACA,aACA,gBAEoB,QAApB,EAAO,UAAsB,EAAO,OAAQ,CAC5C,GAAI,EAAK,WAAiC,UAApB,EAAO,SAAsB,CAE/C,MAAM,GAAM,EAAI,SAAS,uBAAsB,EAAI,WAAW,cAAc,EAAO,UACnF,EAAI,WAAW,eAAe,EAAO,OAAQ,GAC7C,KAGI,EAAI,SAAS,qBAAqB,EAAO,OAC7C,CACA,MAAO,GACiB,UAAhB,EAAO,MACP,MAAM,IAAI,KAAK,sCAAuC,CAClD,4DACA,6DACA,gEACA,qCACA,oEACA,kEACA,yDAGZ,CACJ,OACM,EAAI,QAAQ,OAAO,EAAO,OACpC,CACJ,EACA,EAAI,aAAa,WACrB,CACA,QAAQ,KAAO","file":"/npm/@bjrmatos/pkg@5.8.3/lib-es5/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@bjrmatos/pkg@5.8.3/lib-es5/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n/* eslint-disable require-atomic-updates */\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.exec = void 0;\nconst assert_1 = __importDefault(require(\"assert\"));\nconst fs_extra_1 = require(\"fs-extra\");\nconst minimist_1 = __importDefault(require(\"minimist\"));\nconst pkg_fetch_1 = require(\"pkg-fetch\");\nconst path_1 = __importDefault(require(\"path\"));\nconst log_1 = require(\"./log\");\nconst help_1 = __importDefault(require(\"./help\"));\nconst common_1 = require(\"./common\");\nconst packer_1 = __importDefault(require(\"./packer\"));\nconst chmod_1 = require(\"./chmod\");\nconst producer_1 = __importDefault(require(\"./producer\"));\nconst refiner_1 = __importDefault(require(\"./refiner\"));\nconst fabricator_1 = require(\"./fabricator\");\nconst walker_1 = __importDefault(require(\"./walker\"));\nconst compress_type_1 = require(\"./compress_type\");\nconst mach_o_1 = require(\"./mach-o\");\nconst { version } = JSON.parse((0, fs_extra_1.readFileSync)(path_1.default.join(__dirname, '../package.json'), 'utf-8'));\nfunction isConfiguration(file) {\n    return (0, common_1.isPackageJson)(file) || file.endsWith('.config.json');\n}\n// http://www.openwall.com/lists/musl/2012/12/08/4\nconst { hostArch, hostPlatform, isValidNodeRange, knownArchs, knownPlatforms, toFancyArch, toFancyPlatform, } = pkg_fetch_1.system;\n// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\nconst hostNodeRange = `node${process.version.match(/^v(\\d+)/)[1]}`;\nfunction parseTargets(items) {\n    // [ 'node6-macos-x64', 'node6-linux-x64' ]\n    const targets = [];\n    for (const item of items) {\n        const target = {\n            nodeRange: hostNodeRange,\n            platform: hostPlatform,\n            arch: hostArch,\n        };\n        if (item !== 'host') {\n            for (const token of item.split('-')) {\n                if (!token) {\n                    continue;\n                }\n                if (isValidNodeRange(token)) {\n                    target.nodeRange = token;\n                    continue;\n                }\n                const p = toFancyPlatform(token);\n                if (knownPlatforms.indexOf(p) >= 0) {\n                    target.platform = p;\n                    continue;\n                }\n                const a = toFancyArch(token);\n                if (knownArchs.indexOf(a) >= 0) {\n                    target.arch = a;\n                    continue;\n                }\n                throw (0, log_1.wasReported)(`Unknown token '${token}' in '${item}'`);\n            }\n        }\n        targets.push(target);\n    }\n    return targets;\n}\nfunction stringifyTarget(target) {\n    const { nodeRange, platform, arch } = target;\n    return `${nodeRange}-${platform}-${arch}`;\n}\nfunction differentParts(targets) {\n    const nodeRanges = {};\n    const platforms = {};\n    const archs = {};\n    for (const target of targets) {\n        nodeRanges[target.nodeRange] = true;\n        platforms[target.platform] = true;\n        archs[target.arch] = true;\n    }\n    const result = {};\n    if (Object.keys(nodeRanges).length > 1) {\n        result.nodeRange = true;\n    }\n    if (Object.keys(platforms).length > 1) {\n        result.platform = true;\n    }\n    if (Object.keys(archs).length > 1) {\n        result.arch = true;\n    }\n    return result;\n}\nfunction stringifyTargetForOutput(output, target, different) {\n    const a = [output];\n    if (different.nodeRange) {\n        a.push(target.nodeRange);\n    }\n    if (different.platform) {\n        a.push(target.platform);\n    }\n    if (different.arch) {\n        a.push(target.arch);\n    }\n    return a.join('-');\n}\nfunction fabricatorForTarget({ nodeRange, arch }) {\n    let fabPlatform = hostPlatform;\n    if (hostArch !== arch &&\n        (hostPlatform === 'linux' || hostPlatform === 'alpine')) {\n        // With linuxstatic, it is possible to generate bytecode for different\n        // arch with simple QEMU configuration instead of the entire sysroot.\n        fabPlatform = 'linuxstatic';\n    }\n    return {\n        nodeRange,\n        platform: fabPlatform,\n        arch,\n    };\n}\nconst dryRunResults = {};\nasync function needWithDryRun({ forceBuild, nodeRange, platform, arch, }) {\n    const result = await (0, pkg_fetch_1.need)({\n        dryRun: true,\n        forceBuild,\n        nodeRange,\n        platform,\n        arch,\n    });\n    (0, assert_1.default)(['exists', 'fetched', 'built'].indexOf(result) >= 0);\n    dryRunResults[result] = true;\n}\nconst targetsCache = {};\nasync function needViaCache(target) {\n    const s = stringifyTarget(target);\n    let c = targetsCache[s];\n    if (c) {\n        return c;\n    }\n    const { forceBuild, nodeRange, platform, arch } = target;\n    c = await (0, pkg_fetch_1.need)({\n        forceBuild,\n        nodeRange,\n        platform,\n        arch,\n    });\n    targetsCache[s] = c;\n    return c;\n}\nasync function exec(argv2) {\n    var _a, _b;\n    const argv = (0, minimist_1.default)(argv2, {\n        boolean: [\n            'b',\n            'build',\n            'bytecode',\n            'native-build',\n            'd',\n            'debug',\n            'h',\n            'help',\n            'public',\n            'v',\n            'version',\n            'externalModules',\n            'signature',\n        ],\n        string: [\n            '_',\n            'c',\n            'config',\n            'o',\n            'options',\n            'output',\n            'outdir',\n            'out-dir',\n            'out-path',\n            'public-packages',\n            'no-dict',\n            't',\n            'target',\n            'targets',\n            'C',\n            'compress',\n        ],\n        default: { bytecode: true, 'native-build': true, signature: true },\n    });\n    if (argv.h || argv.help) {\n        (0, help_1.default)();\n        return;\n    }\n    // version\n    if (argv.v || argv.version) {\n        // eslint-disable-next-line no-console\n        console.log(version);\n        return;\n    }\n    log_1.log.info(`pkg@${version}`);\n    // debug\n    log_1.log.debugMode = argv.d || argv.debug;\n    // forceBuild\n    const forceBuild = argv.b || argv.build;\n    // doCompress\n    const algo = argv.C || argv.compress || 'None';\n    let doCompress = compress_type_1.CompressType.None;\n    switch (algo.toLowerCase()) {\n        case 'brotli':\n        case 'br':\n            doCompress = compress_type_1.CompressType.Brotli;\n            break;\n        case 'gzip':\n        case 'gz':\n            doCompress = compress_type_1.CompressType.GZip;\n            break;\n        case 'none':\n            break;\n        default:\n            throw (0, log_1.wasReported)(`Invalid compression algorithm ${algo} ( should be None, Brotli or Gzip)`);\n    }\n    if (doCompress !== compress_type_1.CompressType.None) {\n        // eslint-disable-next-line no-console\n        console.log('compression: ', compress_type_1.CompressType[doCompress]);\n    }\n    // _\n    if (!argv._.length) {\n        throw (0, log_1.wasReported)('Entry file/directory is expected', [\n            'Pass --help to see usage information',\n        ]);\n    }\n    if (argv._.length > 1) {\n        throw (0, log_1.wasReported)('Not more than one entry file/directory is expected');\n    }\n    // input\n    let input = path_1.default.resolve(argv._[0]);\n    if (!(0, fs_extra_1.existsSync)(input)) {\n        throw (0, log_1.wasReported)('Input file does not exist', [input]);\n    }\n    if ((await (0, fs_extra_1.stat)(input)).isDirectory()) {\n        input = path_1.default.join(input, 'package.json');\n        if (!(0, fs_extra_1.existsSync)(input)) {\n            throw (0, log_1.wasReported)('Input file does not exist', [input]);\n        }\n    }\n    // inputJson\n    let inputJson;\n    let inputJsonName;\n    if (isConfiguration(input)) {\n        inputJson = JSON.parse(await (0, fs_extra_1.readFile)(input, 'utf-8'));\n        inputJsonName = inputJson.name;\n        if (inputJsonName) {\n            inputJsonName = inputJsonName.split('/').pop(); // @org/foo\n        }\n    }\n    // inputBin\n    let inputBin;\n    if (inputJson) {\n        let { bin } = inputJson;\n        if (bin) {\n            if (typeof bin === 'object') {\n                if (bin[inputJsonName]) {\n                    bin = bin[inputJsonName];\n                }\n                else {\n                    bin = bin[Object.keys(bin)[0]]; // TODO multiple inputs to pkg them all?\n                }\n            }\n            inputBin = path_1.default.resolve(path_1.default.dirname(input), bin);\n            if (!(0, fs_extra_1.existsSync)(inputBin)) {\n                throw (0, log_1.wasReported)('Bin file does not exist (taken from package.json ' +\n                    \"'bin' property)\", [inputBin]);\n            }\n        }\n    }\n    if (inputJson && !inputBin) {\n        throw (0, log_1.wasReported)(\"Property 'bin' does not exist in\", [input]);\n    }\n    // inputFin\n    const inputFin = inputBin || input;\n    // config\n    let config = argv.c || argv.config;\n    if (inputJson && config) {\n        throw (0, log_1.wasReported)(\"Specify either 'package.json' or config. Not both\");\n    }\n    // configJson\n    let configJson;\n    if (config) {\n        config = path_1.default.resolve(config);\n        if (!(0, fs_extra_1.existsSync)(config)) {\n            throw (0, log_1.wasReported)('Config file does not exist', [config]);\n        }\n        // eslint-disable-next-line import/no-dynamic-require, global-require\n        configJson = require(config); // may be either json or js\n        if (!configJson.name &&\n            !configJson.files &&\n            !configJson.dependencies &&\n            !configJson.pkg) {\n            // package.json not detected\n            configJson = { pkg: configJson };\n        }\n    }\n    // output, outputPath\n    let output = argv.o || argv.output;\n    let outputPath = argv['out-path'] || argv.outdir || argv['out-dir'];\n    let autoOutput = false;\n    if (output && outputPath) {\n        throw (0, log_1.wasReported)(\"Specify either 'output' or 'out-path'. Not both\");\n    }\n    if (!output) {\n        let name;\n        if (inputJson) {\n            name = inputJsonName;\n            if (!name) {\n                throw (0, log_1.wasReported)(\"Property 'name' does not exist in\", [argv._[0]]);\n            }\n        }\n        else if (configJson) {\n            name = configJson.name;\n        }\n        if (!name) {\n            name = path_1.default.basename(inputFin);\n        }\n        if (!outputPath) {\n            if (inputJson && inputJson.pkg) {\n                outputPath = inputJson.pkg.outputPath;\n            }\n            else if (configJson && configJson.pkg) {\n                outputPath = configJson.pkg.outputPath;\n            }\n            outputPath = outputPath || '';\n        }\n        autoOutput = true;\n        const ext = path_1.default.extname(name);\n        output = name.slice(0, -ext.length || undefined);\n        output = path_1.default.resolve(outputPath || '', output);\n    }\n    else {\n        output = path_1.default.resolve(output);\n    }\n    // targets\n    const sTargets = argv.t || argv.target || argv.targets || '';\n    if (typeof sTargets !== 'string') {\n        throw (0, log_1.wasReported)(`Something is wrong near ${JSON.stringify(sTargets)}`);\n    }\n    let targets = parseTargets(sTargets.split(',').filter((t) => t));\n    if (!targets.length) {\n        let jsonTargets;\n        if (inputJson && inputJson.pkg) {\n            jsonTargets = inputJson.pkg.targets;\n        }\n        else if (configJson && configJson.pkg) {\n            jsonTargets = configJson.pkg.targets;\n        }\n        if (jsonTargets) {\n            targets = parseTargets(jsonTargets);\n        }\n    }\n    if (!targets.length) {\n        if (!autoOutput) {\n            targets = parseTargets(['host']);\n            (0, assert_1.default)(targets.length === 1);\n        }\n        else {\n            targets = parseTargets(['linux', 'macos', 'win']);\n        }\n        log_1.log.info('Targets not specified. Assuming:', `${targets.map((t) => stringifyTarget(t)).join(', ')}`);\n    }\n    // differentParts\n    const different = differentParts(targets);\n    // targets[].output\n    for (const target of targets) {\n        let file;\n        if (targets.length === 1) {\n            file = output;\n        }\n        else {\n            file = stringifyTargetForOutput(output, target, different);\n        }\n        if (target.platform === 'win' && path_1.default.extname(file) !== '.exe') {\n            file += '.exe';\n        }\n        target.output = file;\n    }\n    // bakes\n    const bakes = (argv.options || '')\n        .split(',')\n        .filter((bake) => bake)\n        .map((bake) => `--${bake}`);\n    // check if input is going\n    // to be overwritten by output\n    for (const target of targets) {\n        if (target.output === inputFin) {\n            if (autoOutput) {\n                target.output += `-${target.platform}`;\n            }\n            else {\n                throw (0, log_1.wasReported)('Refusing to overwrite input file', [inputFin]);\n            }\n        }\n    }\n    // fetch targets\n    const { bytecode } = argv;\n    const nativeBuild = argv['native-build'];\n    for (const target of targets) {\n        target.forceBuild = forceBuild;\n        await needWithDryRun(target);\n        target.fabricator = fabricatorForTarget(target);\n        if (bytecode) {\n            await needWithDryRun(Object.assign(Object.assign({}, target.fabricator), { forceBuild }));\n        }\n    }\n    if (dryRunResults.fetched && !dryRunResults.built) {\n        log_1.log.info('Fetching base Node.js binaries to PKG_CACHE_PATH');\n    }\n    for (const target of targets) {\n        target.binaryPath = await needViaCache(target);\n        const f = target.fabricator;\n        if (f && bytecode) {\n            f.binaryPath = await needViaCache(f);\n            if (f.platform === 'macos') {\n                // ad-hoc sign the base binary temporarily to generate bytecode\n                // due to the new mandatory signing requirement\n                const signedBinaryPath = `${f.binaryPath}-signed`;\n                await (0, fs_extra_1.remove)(signedBinaryPath);\n                (0, fs_extra_1.copyFileSync)(f.binaryPath, signedBinaryPath);\n                try {\n                    (0, mach_o_1.signMachOExecutable)(signedBinaryPath);\n                }\n                catch (_c) {\n                    throw (0, log_1.wasReported)('Cannot generate bytecode', [\n                        'pkg fails to run \"codesign\" utility. Due to the mandatory signing',\n                        'requirement of macOS, executables must be signed. Please ensure the',\n                        'utility is installed and properly configured.',\n                    ]);\n                }\n                f.binaryPath = signedBinaryPath;\n            }\n            if (f.platform !== 'win') {\n                await (0, chmod_1.plusx)(f.binaryPath);\n            }\n        }\n    }\n    // marker\n    let marker;\n    if (configJson) {\n        marker = {\n            config: configJson,\n            base: path_1.default.dirname(config),\n            configPath: config,\n        };\n    }\n    else {\n        marker = {\n            config: inputJson || {},\n            base: path_1.default.dirname(input),\n            configPath: input,\n        };\n    }\n    marker.toplevel = true;\n    // public\n    const params = {};\n    if (argv.public) {\n        params.publicToplevel = true;\n    }\n    if (argv['public-packages']) {\n        params.publicPackages = argv['public-packages'].split(',');\n        if (((_a = params.publicPackages) === null || _a === void 0 ? void 0 : _a.indexOf('*')) !== -1) {\n            params.publicPackages = ['*'];\n        }\n    }\n    if (argv['no-dict']) {\n        params.noDictionary = argv['no-dict'].split(',');\n        if (((_b = params.noDictionary) === null || _b === void 0 ? void 0 : _b.indexOf('*')) !== -1) {\n            params.noDictionary = ['*'];\n        }\n    }\n    // records\n    let records;\n    let entrypoint = inputFin;\n    let symLinks;\n    const addition = isConfiguration(input) ? input : undefined;\n    const walkResult = await (0, walker_1.default)(marker, entrypoint, addition, params);\n    entrypoint = walkResult.entrypoint;\n    records = walkResult.records;\n    symLinks = walkResult.symLinks;\n    const refineResult = (0, refiner_1.default)(records, entrypoint, symLinks);\n    entrypoint = refineResult.entrypoint;\n    records = refineResult.records;\n    symLinks = refineResult.symLinks;\n    let baseDir;\n    if (argv.externalModules === true) {\n        log_1.log.debug('Require of external modules will be allowed..');\n        baseDir = Object.keys(records).find((pathKey) => records[pathKey].file === marker.base);\n    }\n    const backpack = (0, packer_1.default)({ records, entrypoint, bytecode, symLinks });\n    log_1.log.debug('Targets:', JSON.stringify(targets, null, 2));\n    for (const target of targets) {\n        if (target.output && (0, fs_extra_1.existsSync)(target.output)) {\n            if ((await (0, fs_extra_1.stat)(target.output)).isFile()) {\n                await (0, fs_extra_1.remove)(target.output);\n            }\n            else {\n                throw (0, log_1.wasReported)('Refusing to overwrite non-file output', [\n                    target.output,\n                ]);\n            }\n        }\n        else if (target.output) {\n            await (0, fs_extra_1.mkdirp)(path_1.default.dirname(target.output));\n        }\n        const vfsOutput = argv.vfsOutput ? path_1.default.resolve(argv.vfsOutput) : undefined;\n        await (0, producer_1.default)({\n            backpack,\n            bakes,\n            baseDir,\n            vfsOutput,\n            slash: target.platform === 'win' ? '\\\\' : '/',\n            target: target,\n            symLinks,\n            doCompress,\n            nativeBuild,\n        });\n        if (target.platform !== 'win' && target.output) {\n            if (argv.signature && target.platform === 'macos') {\n                // patch executable to allow code signing\n                const buf = (0, mach_o_1.patchMachOExecutable)((0, fs_extra_1.readFileSync)(target.output));\n                (0, fs_extra_1.writeFileSync)(target.output, buf);\n                try {\n                    // sign executable ad-hoc to workaround the new mandatory signing requirement\n                    // users can always replace the signature if necessary\n                    (0, mach_o_1.signMachOExecutable)(target.output);\n                }\n                catch (_d) {\n                    if (target.arch === 'arm64') {\n                        log_1.log.warn('Unable to sign the macOS executable', [\n                            'Due to the mandatory code signing requirement, before the',\n                            'executable is distributed to end users, it must be signed.',\n                            'Otherwise, it will be immediately killed by kernel on launch.',\n                            'An ad-hoc signature is sufficient.',\n                            'To do that, run pkg on a Mac, or transfer the executable to a Mac',\n                            'and run \"codesign --sign - <executable>\", or (if you use Linux)',\n                            'install \"ldid\" utility to PATH and then run pkg again',\n                        ]);\n                    }\n                }\n            }\n            await (0, chmod_1.plusx)(target.output);\n        }\n    }\n    (0, fabricator_1.shutdown)();\n}\nexports.exec = exec;\n"]}