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

how to include third party javascript libraries? #46

Open
fippo opened this issue Feb 18, 2020 · 18 comments
Open

how to include third party javascript libraries? #46

fippo opened this issue Feb 18, 2020 · 18 comments

Comments

@fippo
Copy link

fippo commented Feb 18, 2020

In this chrome CL I tried adding a third-party library for dealing with SDP in webrtc tests. I put a trimmed down version of the code, a README specifying where to obtain it and a LICENSE file into a directory under the one with the tests using it. @foolip was summoned and asked me to raise the issue here.

How should javascript libraries that are third-party be treated? "Third party" in the sense "they existed before, they are independent from wpt and someone else maintains them"

I assume fetching them from the network is off the table since there should be no runtime dependency on the network.

Should they put in a central place so they can be ignored by linters? If they are only used by a particular spec (nothing else on the web uses SDP thankfully) is a place like <spec>/resources/ better.
Should a package manager (npm, yarn, ...) be used? With or without lockfiles etc.
What is the process for updating them (e.g. npm audit)? Should local modifications be avoided?
Are there licensing concerns that need to be taken care of?

Lots of questions...
in this particular case i'm happy to use the same pattern that is used for webidl2.js

@jgraham
Copy link
Contributor

jgraham commented Feb 18, 2020

My point of view:

  • Use <spec>/third_party for third party code
  • We can write a rule to exclude all third_party directories from linting
  • The best way to add them is typically using git subtree, in case local modifications are required (but local modifications are discouraged in general I'd say). Note that merging subtrees required a direct push to preserve the tree shape.
  • I don't think we want to use a package manager here if possible. The case where it might not be is where we can't include source directly but need to include the output of a build step.
  • Updating is hard; when we vendor stuff we lose the support of most tools that can check for outdated versions (I think).
  • License needs to be compatible with the overall BSD license. So things like GPL dependencies are problematic (by which I think I mean "not possible to include")

@Hexcles
Copy link
Member

Hexcles commented Feb 18, 2020

The best way to add them is typically using git subtree, in case local modifications are required (but local modifications are discouraged in general I'd say). Note that merging subtrees required a direct push to preserve the tree shape.
I don't think we want to use a package manager here if possible. The case where it might not be is where we can't include source directly but need to include the output of a build step.
Updating is hard; when we vendor stuff we lose the support of most tools that can check for outdated versions (I think).

Vendoring third-party code and using a package manager are not mutually exclusive, if we choose not to use git subtree.

For npm packages, I actually think we should use a package manager, and check in the fetched source code. This solves the problem both for vendors (use the checked in source code directly) and authors (easy to upgrade using npm up), at the cost of losing the detailed version history (which doesn't really matter as long as we don't make local modifications). We probably want to use yarn for its flat mode.

@fippo
Copy link
Author

fippo commented Feb 23, 2020

I took a stab at the "use yarn" approach. Branch here

The package.json files can the pretty small thankfully, only listing dependencies. npm and yarn complain about a missing license field but that is just a warning.
Checking in node_modules required git add -f since node_modules is in the root .gitignore. -f solves the problem however.

One thing I didn't like was checking in the full package including documentation, tests etc. I think having a .gitignore to just 🍒-pick what is needed may reduce the size considerably. But when i looked at least in the case of the sdp package the tests were already not included in the npm package.

fippo added a commit to fippo/web-platform-tests that referenced this issue Feb 24, 2020
adds a third-party module for SDP parsing, mangling and generation to the
webrtc directory. This is going to be used for simulcast tests.

Checks in node_modules as well as a package.json and yarn lock files for
ease of updating. See
  web-platform-tests/rfcs#46
for discussіon on the approach
@fippo
Copy link
Author

fippo commented Feb 24, 2020

made a PR from the branch

@snuggs
Copy link

snuggs commented Feb 25, 2020

@fippo this can turn into a ton of technical debt very fast as i'm sure you already know. Also not sure what happens from breaking typical node conventions of traversing node_modules location. Then I realized this isn't a node project per se and the minimum we need is sdp.js. Luckily this package is fairly tight. So seems like an easy band aid. Our future selves may not be so lucky with other third_party so great to discuss. :-).

My vote/opinion is for placing sdp.js (wherever is agreed upon), reference it where needed, and call it a day. However this strategy still doesn't avoid needing to check externally for updates. It's already commonplace (i.e. Tree Shaking) to strip what we don't need (down to the method). If we need a license can throw it at the head. Perhaps i'm thinking too lazy but never been told that's a bad thing 😎

FWIW just my 2 satoshis. 👍 👍 on the sdp js lib though. Personally it's been helpful numerous times in the past. 🙏

@fippo
Copy link
Author

fippo commented Mar 10, 2020

ping - if you folks could take a look at the PR

@alvestrand just proposed another creative test in which this library would be super helpful :-)

@stephenmcgruer
Copy link
Contributor

Hi all, sorry for the delay. I discussed this with @jgraham and @Hexcles today, and we're happy for the proposal from @snuggs to go ahead. That is:

i. Add a new directory, webrtc/third_party/sdp
ii. Vendor (copy) sdp.js and its associated LICENSE file into webrtc/third_party/sdp
iii. Add lint rules to ensure that third_party directories are excluded from linting presubmits.

This is us (deliberately) deferring on an overall policy for third-party javascript in WPT, but hopefully unblocking your current efforts.

I am happy to work on (iii), and look to yourselves to arrange (i) and (ii), if this meets your needs. Thanks!

stephenmcgruer added a commit to web-platform-tests/wpt that referenced this issue Mar 27, 2020
jgraham pushed a commit to web-platform-tests/wpt that referenced this issue Mar 27, 2020
fippo added a commit to fippo/web-platform-tests that referenced this issue Mar 31, 2020
Adds the third-party sdp module
  https://www.npmjs.com/package/sdp
in version 2.12.0 and commit
  958f22a94231e4c1ca651b4a7d53b0e32bb4a558
without tests or dependencies.

See web-platform-tests/rfcs#46 for discussion
on how to add third-party javascript.
fippo added a commit to fippo/web-platform-tests that referenced this issue Mar 31, 2020
Adds the third-party sdp module available from
  https://www.npmjs.com/package/sdp
in version 2.12.0 and commit
  958f22a94231e4c1ca651b4a7d53b0e32bb4a558
without tests or dependencies. This is going to be used by simulcast
tests and is generally useful in manipulating the SDP generated and
consumed by WebRTC.

See web-platform-tests/rfcs#46 for discussion
on how to add third-party javascript libraries.
@fippo
Copy link
Author

fippo commented Mar 31, 2020

Thank you (also Harald for pinging)! Made a new PR referenced above this comment, lint seems to be a solved problem ❤️

xeonchen pushed a commit to xeonchen/gecko that referenced this issue Mar 31, 2020
…es for lint, a=testonly

Automatic update from web-platform-tests
Ignore test suite third_party/ directories for lint

See web-platform-tests/rfcs#46

--

wpt-commits: a0d78a7e1b038652bc6d65170f3e994475ecff9c
wpt-pr: 22498
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Mar 31, 2020
…es for lint, a=testonly

Automatic update from web-platform-tests
Ignore test suite third_party/ directories for lint

See web-platform-tests/rfcs#46

--

wpt-commits: a0d78a7e1b038652bc6d65170f3e994475ecff9c
wpt-pr: 22498
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Apr 1, 2020
…es for lint, a=testonly

Automatic update from web-platform-tests
Ignore test suite third_party/ directories for lint

See web-platform-tests/rfcs#46

--

wpt-commits: a0d78a7e1b038652bc6d65170f3e994475ecff9c
wpt-pr: 22498

UltraBlame original commit: 58f3a4861472c450cdef0048ef42b0de5a935739
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Apr 1, 2020
…es for lint, a=testonly

Automatic update from web-platform-tests
Ignore test suite third_party/ directories for lint

See web-platform-tests/rfcs#46

--

wpt-commits: a0d78a7e1b038652bc6d65170f3e994475ecff9c
wpt-pr: 22498

UltraBlame original commit: 58f3a4861472c450cdef0048ef42b0de5a935739
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Apr 1, 2020
…es for lint, a=testonly

Automatic update from web-platform-tests
Ignore test suite third_party/ directories for lint

See web-platform-tests/rfcs#46

--

wpt-commits: a0d78a7e1b038652bc6d65170f3e994475ecff9c
wpt-pr: 22498

UltraBlame original commit: 58f3a4861472c450cdef0048ef42b0de5a935739
jan-ivar pushed a commit to web-platform-tests/wpt that referenced this issue Apr 2, 2020
* webrtc: add third-party sdp module

Adds the third-party sdp module available from
  https://www.npmjs.com/package/sdp
in version 2.12.0 and commit
  958f22a94231e4c1ca651b4a7d53b0e32bb4a558
without tests or dependencies. This is going to be used by simulcast
tests and is generally useful in manipulating the SDP generated and
consumed by WebRTC.

See web-platform-tests/rfcs#46 for discussion
on how to add third-party javascript libraries.

* add readme
xeonchen pushed a commit to xeonchen/gecko that referenced this issue Apr 6, 2020
…stonly

Automatic update from web-platform-tests
webrtc: add third-party sdp module (#22557)

* webrtc: add third-party sdp module

Adds the third-party sdp module available from
  https://www.npmjs.com/package/sdp
in version 2.12.0 and commit
  958f22a94231e4c1ca651b4a7d53b0e32bb4a558
without tests or dependencies. This is going to be used by simulcast
tests and is generally useful in manipulating the SDP generated and
consumed by WebRTC.

See web-platform-tests/rfcs#46 for discussion
on how to add third-party javascript libraries.

* add readme
--

wpt-commits: 1c48b9809aa82de28b0b450949c2a32590bc61bd
wpt-pr: 22557
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 6, 2020
…stonly

Automatic update from web-platform-tests
webrtc: add third-party sdp module (#22557)

* webrtc: add third-party sdp module

Adds the third-party sdp module available from
  https://www.npmjs.com/package/sdp
in version 2.12.0 and commit
  958f22a94231e4c1ca651b4a7d53b0e32bb4a558
without tests or dependencies. This is going to be used by simulcast
tests and is generally useful in manipulating the SDP generated and
consumed by WebRTC.

See web-platform-tests/rfcs#46 for discussion
on how to add third-party javascript libraries.

* add readme
--

wpt-commits: 1c48b9809aa82de28b0b450949c2a32590bc61bd
wpt-pr: 22557
@foolip
Copy link
Member

foolip commented May 14, 2020

As part of web-platform-tests/wpt#21855 I've spotted another third party JavaScript library in the repo, https://github.com/nodeca/pako added in web-platform-tests/wpt#19614.

foolip added a commit to web-platform-tests/wpt that referenced this issue May 14, 2020
This is following the directory structure used for webrtc in
web-platform-tests/rfcs#46.

Spotted via #21855.
foolip added a commit to web-platform-tests/wpt that referenced this issue May 14, 2020
This is following the directory structure used for webrtc in
web-platform-tests/rfcs#46.

Spotted via #21855.
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue May 26, 2020
…ty directory, a=testonly

Automatic update from web-platform-tests
[compression] move pako into a third_party directory (#23592)

This is following the directory structure used for webrtc in
web-platform-tests/rfcs#46.

Spotted via web-platform-tests/wpt#21855.
--

wpt-commits: 66e875b5d6bbd71ab24af9ca27d341f242f7a7cb
wpt-pr: 23592
xeonchen pushed a commit to xeonchen/gecko that referenced this issue May 26, 2020
…ty directory, a=testonly

Automatic update from web-platform-tests
[compression] move pako into a third_party directory (#23592)

This is following the directory structure used for webrtc in
web-platform-tests/rfcs#46.

Spotted via web-platform-tests/wpt#21855.
--

wpt-commits: 66e875b5d6bbd71ab24af9ca27d341f242f7a7cb
wpt-pr: 23592
@zcorpan
Copy link
Member

zcorpan commented Jun 9, 2020

Noting for the record another PR adding third-party code: web-platform-tests/wpt#23789

It seems to me that right now #46 (comment) is the de-facto overall policy.

@jgraham
Copy link
Contributor

jgraham commented Jun 9, 2020

I am somewhat concerned by PRs like that randomly adding third party code under different licenses all over the tree. @foolip started looking at lints for this; I wonder if we could check whether people are adding either LICENSE files or code with a license block outside of third_party directories, and make that check impossible to disable, in addition to the proposed check for LICENSE files in general with a list of vetted directories.

@foolip
Copy link
Member

foolip commented Jun 9, 2020

I've commented on web-platform-tests/wpt#21855 (comment) about the difficulties I ran into and closed the PR to make it clear I'm not making any progress on it, and don't expect to.

@stephenmcgruer
Copy link
Contributor

So, we can never stop people adding third party code without us knowing; they could simply copy stuff from any library into a test file and there's no way we can detect that.

So, we should concentrate on common things people may do that we can detect, which to me is this list:

  • Introduce a third_party/foo directory
  • Add a LICENSE or LICENSE.md file (basically any file with LICENSE in the name)
  • Add a file with a license block in it (I'm not clear how detectable this one is).

It seems to me that adding third-party libraries should be relatively rare, so perhaps we should be strict about this. What about having the following lints:

  1. A path-lint checking for modifying a file with third_party/ in its name.
  2. A path-lint checking for modifying a file named LICENSE (or with that text in its name).

Then we would explicitly allow specific third_party directories in lint.ignore, which today would be:

*: webrtc/third_party/sdp/*
*: compression/third_party/pako/*

@jgraham
Copy link
Contributor

jgraham commented Jun 22, 2020

I think that makes sense, although I'm not fully clear on the details of what you want to lint. I think we can enforce two things:

  • Every file with LICENSE in its name is a lint error unless it's in a directory called third_party
  • Every third_party directory is an error unless it's listed in the ignore rules. In those rules we should break down the listing by license to set an expectation that adding specific licenses is OK and unknown ones require more investigation.

Other files with a license block are somewhat detectable with a regex lint although it's obviously going to be pretty best-effort.

@stephenmcgruer
Copy link
Contributor

  • Every file with LICENSE in its name is a lint error unless it's in a directory called third_party
  • Every third_party directory is an error unless it's listed in the ignore rules. In those rules we should break down the listing by license to set an expectation that adding specific licenses is OK and unknown ones require more investigation.

Yep, these are what I want to lint :). (actually I had missed the first one, which I think is great!).

Ok, I'll work on the lint change, and maybe do some documentation work too.

@stephenmcgruer
Copy link
Contributor

Every file with LICENSE in its name is a lint error unless it's in a directory called third_party

Violations of this rule:

ERROR:lint:webgpu/LICENSE.txt: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:css/CSS2/LICENSE-BSD: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:css/CSS2/LICENSE-W3CD: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:css/CSS2/LICENSE-W3CTS: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:css/css-color/LICENSE: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:fonts/CSSTest/LICENSE: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:fonts/adobe-fonts/LICENSE: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:fonts/noto/NotoSansAdlam-hinted/LICENSE_OFL.txt: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:fonts/noto/NotoSansCypriot-hinted/LICENSE_OFL.txt: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:html/canvas/tools/LICENSE.txt: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)
ERROR:lint:css/css-ui/support/PTS/PngSuite.LICENSE: License files (e.g. LICENSE.md) must be grandchildren of a third_party directory, e.g. third_party/foo/LICENSE.md (LICENSE-LOCATION)

@jgraham
Copy link
Contributor

jgraham commented Jun 23, 2020

@foolip looked at some of these

https://bugzilla.mozilla.org/show_bug.cgi?id=1637924 is filed for the css-color issue but is waiting for @dbaron I think we can also assume that fonts is all third party. So that leaves webgpu, CSS2, html/canvas/tools and css/css-ui/support/PTS/ to investigate.

@stephenmcgruer
Copy link
Contributor

CSS2 is web-platform-tests/wpt#23593, which is waiting on @wseltzer I believe.

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

7 participants