Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI dependency and installation of additional packages when compilation is done programmatically #1485

Open
alejandroclaro opened this issue Sep 9, 2020 · 1 comment

Comments

@alejandroclaro
Copy link

alejandroclaro commented Sep 9, 2020

protobuf.js version: 6.10.1

I have developed a plugin for a rollup that generate the typescript definition files (.d.ts) using the programmatic interface of protobuf.js

const { createFilter } = require('rollup-pluginutils');
const ProtoBuf = require('protobufjs');
const compile = require('protobufjs/cli/targets/static-module');

function onload(error, root, resolve, reject) {
  const options = {
    'wrap': 'es6',
    'es6': true,
    'forceNumber': true,
    'create': true,
    'encode': true,
    'decode': true,
    'delimited': true,
    'verify': true
  };

  if (error) {
    reject(error);
  } else {
    compile(root, options, (error, code) => onCompilationCompleted(error, code, resolve, reject));
  }
}

function transform(filter, content, id) {
  const pattern = /\.proto$/;

  if (!pattern.test(id) || !filter(id)) {
    return null;
  }

  return new Promise((resolve, reject) => {
    new ProtoBuf.Root().load(id, {}, (error, root) => onload(error, root, resolve, reject));
  });
}

However, even that it looks like this does not need to perform everything the CLI does when the plugin is executed, additional dependencies are installed. So it looks like there is a reference to 'pbts.js' or 'pbjs.js' someware and 'utils.setup()' is invoked.

Besides the fact this looks like hidden dependencies, it's introducing some issues in some environments like in monorepo because sometimes the installation of the dependencies fails. The behavior and issue is very similar to what has been described in #716.

I see no reason to depend on the CLI and all of its dependencies in this use case. Looks like there is a problem with the separation of concerns here.

@ahippler
Copy link

will be fixed by #1234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants