Skip to content

feat: pnpm store add command#1268

Merged
zkochan merged 11 commits intomasterfrom
store-add-cmd
Jul 10, 2018
Merged

feat: pnpm store add command#1268
zkochan merged 11 commits intomasterfrom
store-add-cmd

Conversation

@etamponi
Copy link
Copy Markdown
Member

@etamponi etamponi commented Jul 9, 2018

No description provided.

@etamponi etamponi requested a review from zkochan as a code owner July 9, 2018 17:14
Comment thread packages/supi/src/api/storeAdd.ts Outdated

const pkgIds = []
for (const dep of deps) {
const ret = await opts.storeController.requestPackage(dep, {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you can run them all simultaneously because that is how it works during regular installation (there is a network concurrency limit inside package-requester).

const pkgIds = await Promise.all(deps.map(...

Comment thread packages/supi/src/api/storeAdd.ts Outdated
const deps = await parseWantedDependencies(fuzzyDeps, {
allowNew: true,
currentPrefs: {},
defaultTag: '',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you could pass in the tag config from pnpm. It is a config that is "latest" by default.

Comment thread packages/supi/src/api/storeAdd.ts Outdated
pkgIds.push(ret.body.id)
}

await opts.storeController.updateConnections(opts.prefix, {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As far as I remember, this is not the desired behavior because you don't want this prefix to be added to store.json

I think what we can do is, make package requester add the new fields to storeIndex right after downloading the packages to the store.

Then calling updateConnections won't be needed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As you can see, storeIndex is passed in to package-requester
https://github.com/pnpm/package-store/blob/master/src/storeController/index.ts#L55

so you can just add the field in package-requester like it is done in package-store currently (but just add an empty array)

https://github.com/pnpm/package-store/blob/master/src/storeController/index.ts#L91

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure what you mean with this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

with the implementation you did, an entry like this well be added to store.json:

"registry.npmjs.com/foo/1.0.0": ["/home/usr"],

but what you need is:

"registry.npmjs.com/foo/1.0.0": [],

await storeAdd(['express@4.16.3'], opts as any) // tslint:disable-line

await project.storeHas('express', '4.16.3')
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

might be good to also test the content of store.json

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

storeHas already checks the content of store.json

@etamponi
Copy link
Copy Markdown
Member Author

etamponi commented Jul 10, 2018 via email

@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jul 10, 2018

I meant that requestPackage would add the empty array in all cases. I think it would make sense because the package is in the store but it does not have any connections yet

@etamponi
Copy link
Copy Markdown
Member Author

etamponi commented Jul 10, 2018 via email

@etamponi
Copy link
Copy Markdown
Member Author

I'll add the test that checks store.json after you release the new version of package-requester

zkochan pushed a commit to pnpm/package-requester that referenced this pull request Jul 10, 2018
Comment thread packages/supi/src/api/storeAdd.ts Outdated
const deps = await parseWantedDependencies(fuzzyDeps, {
allowNew: true,
currentPrefs: {},
defaultTag: opts.tag || 'default',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the default should be 'latest'

Comment thread packages/supi/src/api/storeAdd.ts Outdated
registry: normalizeRegistryUrl(opts.registry || 'https://registry.npmjs.org/'),
verifyStoreIntegrity: opts.verifyStoreIntegrity || true,
})
await pkgResponse['fetchingFiles'].catch((err: Error) => {}) // tslint:disable-line
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there should be an info message printed about the added tarballs.
When you run pnpm store add typescript@1 it would be useful to see which version of typescript was added. So maybe just print the pkgId?

$ pnpm store add typescript@1
+ registry.npmjs.org/typescript/1.2.1

pnpm store prune provides a similar output at the moment.

Also, I think it is important to print failures. So don't just ignore if fetchingFiles fails. Maybe the process should exit with a non-zero exit code. Fetching the package is the intention of the operation after all, so if it fails, the operation was not successful.

Comment thread packages/supi/test/storeAdd.ts Outdated
await project.storeHas('express', '4.16.3')

const storeIndex = await loadJsonFile(path.join(opts.store, 'store.json'))
t.deepEqual(storeIndex['localhost+4873/express/4.16.3'], [])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can make a deepEqual of the whole file because it should be empty

t.deepEqual(storeIndex, {
  'localhost+4873/express/4.16.3': [],
})

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it also contains another package, I needed to install it to initialize the store in the test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh, I see. But that's an issue, isn't it? I think pnpm store add should be able to create a new store

Copy link
Copy Markdown
Member Author

@etamponi etamponi Jul 10, 2018

Choose a reason for hiding this comment

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

It only happens in this test, if I run it from the command line it creates the store correctly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are you sure? When you run it manually, it probably uses your global store that already exists at ~/.pnpm-store but tests use a new store in every test case. So to test it manually, you'd need something like rm -rf store && pnpm store add typescript@1 --store store

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's exactly how I tested it

Comment thread packages/pnpm/src/cmd/help.ts Outdated
Returns a 0 exit code if packages in the store are not modified, i.e. the content of the package is the
same as it was at the time of unpacking.

pnpm store add
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pnpm store add [pkg...] would be more straightforward

Comment thread packages/supi/src/api/storeAdd.ts Outdated
}

if (hasFailures) {
throw new Error('Some packages have not been added correctly')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add an additional test for checking this behavior. You can just add a non-existent package to the store pnpm store add @pnpm/this-does-not-exist

Comment thread packages/supi/src/api/storeAdd.ts Outdated
rawSpec: dep.raw,
},
preferredVersions: {},
prefix: '',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should it work with local tarballs? If you pass in the prefix, it will work with pnpm store add ../some.tgz

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have no idea what the prefix is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it should be passed in by pnpm. prefix is basically the current working directory in most cases

@zkochan zkochan merged commit 7bebfb8 into master Jul 10, 2018
@zkochan zkochan deleted the store-add-cmd branch July 10, 2018 21:10
@zkochan
Copy link
Copy Markdown
Member

zkochan commented Jul 11, 2018

🚢 2.12.0-0

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

Successfully merging this pull request may close these issues.

2 participants