Skip to content

Conversation

@chengcyber
Copy link
Contributor

@chengcyber chengcyber commented Oct 16, 2020

Rollup Plugin Name: @rollup/plugin-wasm

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

For now, wasm plugin is using banner API to inject helper function _loadWasmModule, but it will inject this helper function in every file, even those files is unrelated to wasm things.
After this PR merged, it uses a helper module to inject _loadWasmModule, hopes to help removing the redundant code

@shellscape
Copy link
Collaborator

Thanks for the PR. You've checked the box that tests are included but haven't provided any tests in the PR. Please add tests and we'll review.

@@ -0,0 +1,55 @@
export const HELPERS_ID = '\0wasmHelpers.js';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this null byte prefix do?

Copy link
Contributor Author

@chengcyber chengcyber Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100 percent sure where to find the documentation, but "\0" seems to be a convention when writing rollup plugin to indicate the module comes from a plugin. and if it should not be taken by this plugin, resolveId returns null, otherwise returns the current resolveId

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It indicates a "virtual module" in the Rollup ecosystem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More precisely it means: Other plugins, please ignore this module and please do not apply any transformations etc. https://rollupjs.org/guide/en/#conventions

@chengcyber
Copy link
Contributor Author

chengcyber commented Oct 19, 2020

Thanks for the PR. You've checked the box that tests are included but haven't provided any tests in the PR. Please add tests and we'll review.

Hi @shellscape. No more tests are added in this PR. This is a refactoring for the existing functionality, so it might be good enough to pass all existing tests.

@shellscape
Copy link
Collaborator

Sorry, but we cannot accept pull requests for fixes or features without accompanying tests. You are refactoring some code, but what your refactor attempts to accomplish is a fix. You must write new tests that demonstrate the conditions your changes resolve before we can accept the PR. This requirement exists to protect against future regression.

@chengcyber
Copy link
Contributor Author

Sorry, but we cannot accept pull requests for fixes or features without accompanying tests. You are refactoring some code, but what your refactor attempts to accomplish is a fix. You must write new tests that demonstrate the conditions your changes resolve before we can accept the PR. This requirement exists to protect against future regression.

@shellscape I totally agree to prevent future regression by adding new tests, but kind of confusing about how to add new tests for this refactor. Since IMO the existing tests cover the functionality of the current codebase, and this PR does not add/remove more functionality...(just moving the code in banner to a virtual module).

Could you kindly help to figure out the direction more clear?

@shellscape
Copy link
Collaborator

Sure. You have a clear before/after result. Previously the bundle would contain multiple copies of the helper. With your changes it should contain only one. That's the test.

@chengcyber
Copy link
Contributor Author

@shellscape A test for injecting helper is added, using a custom detect plugin to check whether the module contains inject import. PTAL

t.true(code.includes(injectImport));
}
if (id.endsWith('foo.js')) {
t.true(!code.includes(injectImport));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.true(!code.includes(injectImport));
t.false(code.includes(injectImport));

@shellscape
Copy link
Collaborator

@bminixhofer since you recently contributed here, please have a look at this change.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not test it in detail but looks good to me!

@@ -0,0 +1,55 @@
export const HELPERS_ID = '\0wasmHelpers.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More precisely it means: Other plugins, please ignore this module and please do not apply any transformations etc. https://rollupjs.org/guide/en/#conventions

@bminixhofer
Copy link
Contributor

Looks good to me as well!

@shellscape shellscape merged commit 1bf5b2c into rollup:master Oct 21, 2020
@shellscape
Copy link
Collaborator

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants