GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cache module with same version and same registry by hustxiaoc · Pull Request #3289 · nodejs/node

cache module with same version and same registry #3289

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.

Sign up for GitHub

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

Closed
hustxiaoc wants to merge 1 commit into nodejs:master from hustxiaoc:patch-1

Uh oh!

There was an error while loading. Please reload this page.

Closed

cache module with same version and same registry #3289

Changes from all commits
Commits
Show all changes
1 commit
Select commit
43d874f
cache module with same version and same registry
Oct 9, 2015
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
cache module with same version and same registry
related pr nodejs/node-v0.x-archive#8617
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

淘小杰
淘小杰 committed Oct 9, 2015
commit 43d874f404373e8c057a5db7d18ed8c9a540a68b

There are no files selected for viewing

17 changes: 13 additions & 4 deletions 17 lib/module.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const path = require('path');
const internalModuleReadFile = process.binding('fs').internalModuleReadFile;
const internalModuleStat = process.binding('fs').internalModuleStat;


var moduleCache = {};
// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
Expand Down Expand Up @@ -76,7 +76,7 @@ function readPackage(requestPath) {
}

try {
var pkg = packageMainCache[requestPath] = JSON.parse(json).main;
var pkg = packageMainCache[requestPath] = JSON.parse(json);
Comment thread Outdated

@JacksonTian JacksonTian Oct 9, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

这个会导致内存中带有很多无关信息。

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hustxiaoc hustxiaoc Oct 9, 2015

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

相比于多次加载模块使用的内存少多了

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Oct 9, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you use English please?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
} catch (e) {
e.path = jsonPath;
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
Expand All @@ -88,9 +88,18 @@ function readPackage(requestPath) {
function tryPackage(requestPath, exts) {
var pkg = readPackage(requestPath);

if (!pkg) return false;
if (!(pkg && pkg.main)) return false;

var resolved = pkg['_resolved'],
Comment thread Outdated

@bnoordhuis bnoordhuis Oct 9, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Where does the _resolved property come from?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yaniswang yaniswang Oct 9, 2015

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

{
  "name": "commander",
  "version": "2.6.0",
  "description": "the complete solution for node.js command-line programs",
  "keywords": [
    "command",
    "option",
    "parser",
    "prompt"
  ],
  "author": {
    "name": "TJ Holowaychuk",
    "email": "[email protected]"
  },
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/tj/commander.js.git"
  },
  "devDependencies": {
    "should": ">= 0.0.1"
  },
  "scripts": {
    "test": "make test"
  },
  "main": "index",
  "engines": {
    "node": ">= 0.6.x"
  },
  "files": [
    "index.js"
  ],
  "gitHead": "c6807fd154dd3b7ce8756f141f8d3acfcc74be60",
  "bugs": {
    "url": "https://github.com/tj/commander.js/issues"
  },
  "homepage": "https://github.com/tj/commander.js",
  "_id": "[email protected]",
  "_shasum": "9df7e52fb2a0cb0fb89058ee80c3104225f37e1d",
  "_from": "[email protected]",
  "_npmVersion": "2.1.12",
  "_nodeVersion": "0.11.14",
  "_npmUser": {
    "name": "zhiyelee",
    "email": "[email protected]"
  },
  "maintainers": [
    {
      "name": "tjholowaychuk",
      "email": "[email protected]"
    },
    {
      "name": "somekittens",
      "email": "[email protected]"
    },
    {
      "name": "zhiyelee",
      "email": "[email protected]"
    },
    {
      "name": "thethomaseffect",
      "email": "[email protected]"
    }
  ],
  "dist": {
    "shasum": "9df7e52fb2a0cb0fb89058ee80c3104225f37e1d",
    "tarball": "http://registry.npmjs.org/commander/-/commander-2.6.0.tgz"
  },
  "directories": {},
  "_resolved": "http://registry.npmjs.org/commander/-/commander-2.6.0.tgz",
  "readme": "ERROR: No README data found!"
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Oct 9, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I see. What if _resolved is not as unique as this patch assumes? Things will break badly, won't they?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yaniswang yaniswang Oct 9, 2015

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Or replace to shasum?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Oct 9, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You mean the _shasum field? Same issue: what if it's not unique, e.g., because someone accidentally copy-pasted it from one package.json to another?

You could perhaps take the SHA-1 checksum of the whole package.json file but that requires that node is compiled with openssl support. You can add workarounds for the non-openssl case but I don't know, that gets complex awfully fast.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hustxiaoc hustxiaoc Oct 9, 2015

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

when running npm install , does it not download the source code from the _resolved url ? so the _resolved url got be unique, otherwise things will break badly, right?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fengmk2 fengmk2 Oct 9, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

_resolved is private property from npm registry, should not use it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yaniswang yaniswang Oct 9, 2015

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Or tarball

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
main = pkg.main;

var filename;
if(resolved) {
filename = moduleCache[resolved] || (moduleCache[resolved] = path.resolve(requestPath, main));
}else{
filename = path.resolve(requestPath, main);
}

var filename = path.resolve(requestPath, pkg);
return tryFile(filename) || tryExtensions(filename, exts) ||
tryExtensions(path.resolve(filename, 'index'), exts);
}
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.