feat: publish the minimum files to npm#243
feat: publish the minimum files to npm#243marionebl merged 8 commits intoconventional-changelog:masterfrom ybiquitous:add-files-to-all-package-json
Conversation
|
Thanks a lot! Will have look at this later today! |
marionebl
left a comment
There was a problem hiding this comment.
Got some ideas on how to improve this. We'd need some additional tests checking basic functionality (as in: "can the contents of the tarball be imported / executed as advertised")
| return cwd; | ||
| } | ||
|
|
||
| async function testPackingFiles(t, expectedFiles) { |
There was a problem hiding this comment.
Please do not pass in the testing context - the methods in @packages/test should only provide required setup / side effects. Please check the actual assertions in the test itself.
|
|
||
| // Install pack file | ||
| packFile = path.resolve(await execa.stdout('npm', ['pack'])); | ||
| await execa('npm', ['install', '--no-progress', packFile], {cwd}); |
There was a problem hiding this comment.
I'd prefer reading the file list this from the tarball directly, e.g. via tar-fs.
| import test from 'ava'; | ||
|
|
||
| test('should publish the minimum files', async t => { | ||
| await npm.testPackingFiles(t, [ |
There was a problem hiding this comment.
Instead of specifying the expected bundle files manually I'd like to derive the absolute minimum from package.json entries: main: string = "index.js" and bin: string || { key: string }. This could be done via a helper fn that should live in @commitlint/test
import pkgDir from 'pkg-dir';
import {npm} from '@commitlint/test';
test('should publish required files', async t => {
const cwd = pkgDir(__dirname);
const expected = await npm.getPackageFiles({ cwd });
const actual = await npm.getTarballFiles();
t.deepEquals(actual, expected);
});
|
Thanks for the feedbacks! I try to fix them. 😃 💪 |
marionebl
left a comment
There was a problem hiding this comment.
Great job on improving the test setup, thank you. I have some additional feedback - tell me if I am nitpicking.
| fs | ||
| .createReadStream(tarballFile) | ||
| .pipe(zlib.createGunzip()) | ||
| .pipe(tar.extract(workDir)) |
There was a problem hiding this comment.
I think we could use the ignore options of tar.extract to get a file list without actually writing to disk:
const files = [];
fs.createReadStream(tarballFile)
.pipe(zlib.createGunzip())
.pipe(tar.extract(workDir, {
ignore(name) {
files.push(name);
return true;
}
}))
.once('error', err => reject(err))
.once('finish', () => resolve());Might be elaborate enough to factor it out to a listArchive function.
| }); | ||
|
|
||
| // List all files | ||
| return (await globby(['**'], { |
There was a problem hiding this comment.
Should be obsolete if we implement listArchive
| sander.unlink(packFile); | ||
| } | ||
| sander.rimraf(tarballFile); | ||
| sander.rimraf(workDir); |
There was a problem hiding this comment.
Should be obsolete if we implement listArchive
| const tarballFile = path.resolve(cwd, tarballFilename); | ||
| const workDir = await fix.bootstrap(); | ||
|
|
||
| try { |
There was a problem hiding this comment.
I think we can unwrap this from
try {
// 1
} finally {
// 2
}to
// 1
// 2now the assertions happens in the test body.
There was a problem hiding this comment.
Shouldn't we put clean up code in finally clause?
try {
// do something
finally {
sander.rimraf(tarballFile)
sander.rimraf(workDir)
}There was a problem hiding this comment.
I think we could use the ignore options of tar.extract to get a file list without actually writing to disk:
Sorry. Please ignore my question. We don't need writing to disk 😓
There was a problem hiding this comment.
Sorry for many times...
The following code (npm pack) writes tarball file (e.g. commitlint-cli-6.0.2.tgz) to disk actually.
Should we clean-up this file in finally clause?
const tarballFilename = await execa.stdout('npm', ['pack'], {cwd});
const tarballFile = path.resolve(cwd, tarballFilename);
try {
// do something
} finally {
sander.unlink(tarballFile);
}|
|
||
| async function getPackageFiles({cwd, npmignore}) { | ||
| return (await packlist({path: cwd})) | ||
| .concat(npmignore ? '.npmignore' : []) |
There was a problem hiding this comment.
Because npm-packlist module ignores .npmignore even if it exists. 😓
| const cwd = await pkgDir(__dirname); | ||
| const actual = await npm.getTarballFiles({cwd}); | ||
| const expected = await npm.getPackageFiles({cwd, npmignore: true}); | ||
| t.deepEqual(actual, expected); |
There was a problem hiding this comment.
We should change this to a less strict check, e.g.
// for each file we expect
t.true(includes(actual, 'some-file.js'))
I am rolling around the idea to introduce unexpected to the testing setup. Should make things like this easier.
There was a problem hiding this comment.
That idea makes test code easier, because we don't need implementing code such as npm.packageFiles()! 👍
Is that idea is like the following code, correct?
t.true(actual.includes('package.json')) //<= unnecessary? (because it is obvious)
t.true(actual.includes('README.md'))
t.true(actual.includes('CHANGELOG.md'))
t.true(actual.includes('index.js'))
t.true(actual.includes('lib/cli.js'))
t.true(actual.includes('lib/help.js'))|
@ybiquitous Thanks for starting this. I pushed some changes on top, implementing the more intricate parts of my ideas. Do you want to implement the publish tests for all packages? |
|
I understand well from your pushed code! 😄 |
| return files; | ||
| } | ||
|
|
||
| function getArchveFiles(filePath) { |
There was a problem hiding this comment.
[nitspick] I found typo: getArchveFiles -> getArchiveFiles.
Add new test function to assert publishing files #144
|
@marionebl Great work! 🎉 🎉 🎉 I appreciate so much that you have done the rest of my work. 😊 👍 |
Hi! 😄
I intend to fix #144 by this PR, but I have no confidence whether the new E2E test (
npm.testPackingFilesfunction) is valid. 😓So would you please review this PR especially about new test code?
After reviewing and fixing, I will add
.npmignoreto other packages than@commilint/cli. 💪Description
npm.testPackingFiles.npmignoreto@commitlint/clito review whether testing is validMotivation and Context
N/A
Usage examples
N/A
How Has This Been Tested?
By adding new E2E test.
Types of changes
Checklist: