Sparticuz / chrome-aws-lambda

This package has been deprecated in favor of @sparticuz/chromium
https://www.github.com/sparticuz/chromium
MIT License
139 stars 21 forks source link

[REQUEST] Allow to specify bin directory #20

Closed Townsheriff closed 1 year ago

Townsheriff commented 2 years ago

What would you like to have implemented?

Give an argument to await chromium.executablePath which would specify where binaries are located. For example await chromium.executablePath("./bin").

Why would it be useful?

I'm bundling this library with webpack and in the end I have 1 file, but from the source code I can see that binaries are located path.join(__dirname, "..", "bin") which requires me to submit to this contract. Instead I would like to create a layer or give my own path to binaries.

To create the final dist directory for lambda I'm also using copy plugin to copy binaries to dist directory.

In webpack configuration I'm creating parent directory only to support path.join(__dirname, "..", "bin") contract.

const webpack = require("webpack");
const CopyPlugin = require("copy-webpack-plugin");

module.exports = () => {
  return {
    entry: {
      "api-handler": "./src/handler.ts",
    },
    target: "node",
    mode: "production",
    module: {
      rules: [
        {
          test: /\.ts$/,
          use: "ts-loader",
          exclude: /node_modules/,
        },
      ],
    },
    resolve: {
      extensions: [".ts", ".mjs", ".js"],
    },
    plugins: [
      new webpack.IgnorePlugin({
        // this is another issue with this package
        resourceRegExp: /.*\.js\.map$/,
      }),
      new CopyPlugin({
        patterns: [
          {
            from: "node_modules/@sparticuz/chrome-aws-lambda/bin/",
            to: "async-handler/bin/",
          },
          {
            from: "node_modules/@sparticuz/chrome-aws-lambda/bin/",
            to: "api-handler/bin/",
          },
        ],
      }),
    ],

    output: {
      libraryTarget: "commonjs",
      filename: "[name]/src/index.js",
      clean: true,
    },
  };
};

Huge thanks for maintaining this library.

Cheers, Arturs

Sparticuz commented 2 years ago

https://github.com/Sparticuz/chrome-aws-lambda/issues/28#issuecomment-1238323496

Specify a http target as well