-
Notifications
You must be signed in to change notification settings - Fork 0
chore(cli): prepare npm package for publishing #26
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| 'use strict'; | ||
|
|
||
| const { execSync } = require('child_process'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const packageRoot = path.resolve(__dirname, '..'); | ||
| const forbidden = [/^node_modules\//, /^target\//, /\.env$/, /^scripts\//]; | ||
|
|
||
| function main() { | ||
| const output = execSync('npm pack --dry-run 2>&1', { | ||
| cwd: packageRoot, | ||
| encoding: 'utf8', | ||
| stdio: ['ignore', 'pipe', 'pipe'], | ||
| shell: true, | ||
| }); | ||
|
|
||
| const lines = output.split('\n'); | ||
| const tarballLines = lines.filter((line) => line.startsWith('npm notice ')); | ||
| const fileLines = tarballLines | ||
| .map((line) => line.replace(/^npm notice /, '').trim()) | ||
| .filter((line) => /^[\d.]+[kMG]?B\s+/.test(line)) | ||
| .map((line) => line.replace(/^[\d.]+[kMG]?B\s+/, '')); | ||
|
|
||
| const errors = []; | ||
|
|
||
| for (const file of fileLines) { | ||
| if (forbidden.some((re) => re.test(file))) { | ||
| errors.push(`forbidden path in pack: ${file}`); | ||
| } | ||
| } | ||
|
|
||
| const required = ['package.json', 'README.md', 'bin/codra.js']; | ||
| for (const file of required) { | ||
| if (!fileLines.includes(file)) { | ||
| errors.push(`missing required file: ${file}`); | ||
| } | ||
| } | ||
|
|
||
| const nativeBins = fileLines.filter((f) => f.startsWith('bin/native/')); | ||
| if (nativeBins.length === 0) { | ||
| errors.push('no bin/native/<platform>-<arch>/ binary in pack (run npm run build first)'); | ||
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| console.error('[pack-dry-run] failed:'); | ||
| for (const err of errors) { | ||
| console.error(` - ${err}`); | ||
| } | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log('[pack-dry-run] ok'); | ||
| console.log(`[pack-dry-run] native binaries: ${nativeBins.join(', ')}`); | ||
| process.stdout.write(output); | ||
| } | ||
|
|
||
| main(); | ||
Oops, something went wrong.
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.
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.
Because
packages/codra-npm-cli/.gitignoreexcludesbin/native/, the binary thatprepackbuilds is still omitted from the tarball; I verified npm’s packing behavior by creating a dummybin/native/.../codraand runningnpm pack --dry-run --ignore-scripts, whose tarball contents listed onlyREADME.md,bin/codra.js, andpackage.json. As a result this new check always reportsno bin/native/...after a successful build, and an actualnpm publishwould ship a wrapper that cannot run unless the ignore/packaging rules are changed.Useful? React with 👍 / 👎.