Skip to content

Commit d484d31

Browse files
erickjpcj
authored andcommitted
Fixes #65 (#66)
parse_yarn_lock.js: adds a hack for handling npm version URLs and extends the express test to cover this case.
1 parent 7674456 commit d484d31

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

node/internal/parse_yarn_lock.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ function isPackage(p, s, f) {
7676
}
7777

7878
/**
79-
* Given a list of yarn entries and a target module, find an exact
80-
* match by name and version.
79+
* Given a list of yarn entries and a target module, find an exact match by name
80+
* and version.
8181
*/
8282
function findMatchingYarnEntryByNameAndVersion(entries, module) {
8383
for (let i = 0; i < entries.length; i++) {
@@ -237,9 +237,13 @@ function makeYarnEntry(key, entry) {
237237
* Parse a yarn name into something that will be agreeable to bazel.
238238
*/
239239
function parseName(key, entry) {
240-
// can be '[email protected]' or something like '@types/[email protected]'
241-
const at = key.lastIndexOf('@');
242240
entry.id = key;
241+
242+
// can be '[email protected]' or something like '@types/[email protected]'
243+
// or even something like @types/foo@https://[email protected]/pkg#mod.
244+
// TODO: Regexes would be better here to support more package.json dependency
245+
// formats: https://docs.npmjs.com/files/package.json#dependencies
246+
const at = key.indexOf("@", 1);
243247
entry.name = key.slice(0, at);
244248

245249
const label = entry.name.replace('@', 'at-');

tests/express/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This folder demonstrates the use of node_binary with a node modules
44
dependency that has other modular dependencies. In this case, we're
55
using the `yarn_modules.package_json` attribute rather than the `deps`
6-
attribute to specify the dependency on express. We're also using the
7-
`@yarn_modules//:_all_` pseudo-module target to pull in all the module
8-
dependencies.
6+
attribute to specify the dependency on express. Another dependency on
7+
express-sessoin is added to package.json using a github npm URL. We're
8+
also using the `@yarn_modules//:_all_` pseudo-module target to pull in
9+
all the module dependencies.

tests/express/WORKSPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ node_repositories()
1010
yarn_modules(
1111
name = "yarn_modules",
1212
package_json = "//:package.json",
13+
# Allows yarn to unpack the express-session git repo in package.json
14+
install_tools = ["git"],
1315
)

tests/express/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "server",
33
"version": "1.0.0",
44
"dependencies": {
5-
"express": "4.15.4"
5+
"express": "4.15.4",
6+
"express-session": "git+https://[email protected]/expressjs/session#v1.15.6"
67
}
78
}

tests/express/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const express = require("express");
2+
const session = require('express-session');
23

34
const app = express();
5+
app.use(session({
6+
secret: 'super secret session'
7+
}));
48

59
app.get('/', (req, res) => {
610
res.send('Hello World!');

0 commit comments

Comments
 (0)