Skip to content
This repository was archived by the owner on Sep 10, 2026. It is now read-only.

Add tests for polymer-cli binary - #48

Merged
pcj merged 6 commits into
pubref:masterfrom
Zetten:PolymerCli
Dec 29, 2017
Merged

pcj merged 6 commits into
pubref:masterfrom
Zetten:PolymerCli

Conversation

@Zetten

@Zetten Zetten commented Nov 1, 2017

Copy link
Copy Markdown
Contributor

Attempting to build genrules based on a node_binary for polymer-cli results in errors at several points - initially related to @-scoped module names, but also the TARGET_PATH determination for the binary itself (exposed when a WORKSPACE name is set, and the magic __main__ path is no longer present).

This branch introduces a (failing) test using polymer-cli, similar to the webpack test, and then attempts to resolve the issues.

@Zetten

Zetten commented Nov 1, 2017

Copy link
Copy Markdown
Contributor Author

The polymer init test is apparently not really appropriate for Travis - it was a gamble anyway as I have local issues due to an http_proxy.

I'll try to figure out a better test.

@pcj

pcj commented Nov 1, 2017

Copy link
Copy Markdown
Contributor

Thanks for this @Zetten, polymer-cli will be a good test / complex test case.

@Zetten

Zetten commented Nov 6, 2017

Copy link
Copy Markdown
Contributor Author

The upcoming bazel 0.8.0 release includes the following change:

  • runfiles, sh: Shell scripts may now depend on
    //src/tools/runfiles:runfiles_sh_lib and source runfiles.sh. The
    script defines the rlocation function which returns runfile
    paths on every platform.
  • In addition to $(location), Bazel now also supports $(rootpath)
    to obtain
    the root-relative path (i.e., for runfiles locations), and
    $(execpath) to
    obtain the exec path (i.e., for build-time locations)

I think this might make for a simpler node_binary wrapper script. I'll disable my failing test to get this PR moving, and see whether it can be improved further once 0.8.0 lands.

@pcj

pcj commented Nov 6, 2017 via email

Copy link
Copy Markdown
Contributor

@Zetten

Zetten commented Nov 8, 2017

Copy link
Copy Markdown
Contributor Author

Only one of the OS X Travis builds failed, due to hitting the time limit.

I'm not able to retrigger, but I suspect it's unrelated to the change itself.

@pcj pcj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall I think this looks good, and it's awesome to see it working. I'm ready to merge this, but I'm hoping you can add one last commit to provide a little more explanation for future people to understand how it works. See my specific comments.

Comment thread node/internal/parse_yarn_lock.js Outdated

// For all top-level folders in the node_modules directory that
// For all top-level or @-scoped folders in the node_modules directory that
// contain a package.json file...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you provide a bit more detail here about the change for future people looking at the code? What was it about the deps or structure of the polymer-cli that made this change necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the behaviour is actually what was originally intended and documented. That is, it's not specific to polymer-cli, it was simply (I think) an oversight in the handling of @-scoped dependencies which meant they were omitted from the generated BUILD.bazel.

I'm happy to add more comments if needed though.

Comment thread node/internal/parse_yarn_lock.js Outdated
print(` version = "${module.version}",`);
print(` package_json = "node_modules/${module.name}/package.json",`);
print(` srcs = glob(["node_modules/${module.name}/**/*"], exclude = ["node_modules/${module.name}/package.json"]),`);
print(` srcs = glob(["node_modules/${module.name}/**/*"], exclude = ["node_modules/${module.name}/package.json", "**/* *"]),`);

@pcj pcj Nov 8, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you comment a bit more on the intent here (what files do we want?) I think it will be confusing to future people looking at it.

@Zetten Zetten Nov 8, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This one I'm not sure about.

This was actually a crude workaround to deal with the fact that bazel doesn't like filenames with spaces, and some-dep-I-can't-remember in the polymer-cli tree has such a file.

Ironically it looked like it was a module's test data for filenames with spaces, so my initial instinct was to exclude the test/** tree from the imported modules.

But then I realised anything dealing with that should probably be more firmly dealt with (and documented), e.g. the Gradle client-dependencies-plugin which includes/excludes specific stuff from the imported modules.

clientDependencies {
    fileExtensions = ['css', 'js', 'eot', 'svg', 'ttf', 'woff', 'woff2', 'ts',
                      'jpg', 'jpeg', 'png', 'gif'] // <1>
    releaseFolders = ['dist', 'release'] // <2>
    copyIncludes = [] // <3>
    copyExcludes = ['**/*.min.js', '**/*.min.css', '**/*.map', '**/Gruntfile.js',
                        'gulpfile.js', 'source/**'] // <4>
}

A solution for this in rules_node would have to allow the user to override this behaviour (both generally and for specific modules), so it gets a bit complicated and probably deserves its own PR.

So yeah, the end result was "just exclude files which have a space in the name" - which gets us past the blocker for polymer-cli, with the caveat that we hope none of our dependencies have such files in their real sources (which would otherwise if included cause bazel to choke anyway).

If you're happy with this approach I'll add another comment to the code.

@Zetten

Zetten commented Nov 13, 2017

Copy link
Copy Markdown
Contributor Author

I've added a couple of comments, hopefully it's a bit clearer what the code is trying to do!

@pcj
pcj merged commit 277a65c into pubref:master Dec 29, 2017
@Zetten

Zetten commented Dec 29, 2017

Copy link
Copy Markdown
Contributor Author

Thanks for merging - I'd forgotten about this!

Just FYI I did start looking at how to use the new runfiles features from Bazel 0.8.0 but got a bit sidetracked. I didn't test all the different ways a node_binary can be called, but it should be possible to simplify a couple of the cases at least. I'll try to knock something into shape for a PR in the new year.

@Zetten
Zetten deleted the PolymerCli branch December 29, 2017 16:03
@pcj

pcj commented Dec 29, 2017

Copy link
Copy Markdown
Contributor

Sounds good!

@fkorotkov

Copy link
Copy Markdown

@Zetten @pcj It seems these tests are failing now even though the latest master build is green. The failure is:

INFO: Build completed, 1 test FAILED, 23523 total actions
//:polymer-cli_bin_test                                                  FAILED in 14.4s
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
-----------------------------------------------------------------------------
module.js:472
    throw err;
    ^

Error: Cannot find module 'lazy-req'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/private/var/tmp/_bazel_fedor/3cf928c1983148e1d64fee3f3cf58fdd/execroot/org_pubref_rules_node_polymer_test/bazel-out/darwin-fastbuild/bin/external/yarn_modules/polymer-cli_polymer_bin_files/node_modules/polymer-cli/node_modules/update-notifier/index.js:5:19)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)

I can reproduce it locally and in my fork on Travis CI.

@Zetten

Zetten commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

Yeah, I saw this pop up in my own project recently as well. Somewhere along the way there are two different transitive versions of update-notifier getting pulled in. I think the 2.x line has removed lazy-req as a dependency, so it's missed out across the board, even though update-notifier 1.x is still there and using it.

I didn't dig into the npm/yarn dependency stuff too much (that way madness lies...) but I guess the solution is to fix the version of update-notifier (and possibly other deps too) in the resolutions attribute of the yarn_modules target.

Unfortunately my project has decided to no longer use polymer (and polymer-cli) and I haven't been able to devote any time to figuring out the issue properly.

@Zetten

Zetten commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

I've offered a short workaround in #57. If it recurs I would suggest pinning all transitive dependency versions as a solution.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants