Skip to content
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

feat: create script for omit package.json fields before publish #1005

Merged

Conversation

easymikey
Copy link
Contributor

@easymikey easymikey commented Dec 18, 2024

Create script and test

Fixes #1003

node scripts/clean-package-json.mjs
  • Tests pass
  • Appropriate changes to README are included in PR

@easymikey easymikey changed the title feat: create script for omit field feat: create script for omit package.json field Dec 18, 2024
@easymikey easymikey changed the title feat: create script for omit package.json field feat: create script for omit package.json fields before publish Dec 18, 2024
scripts/clean-package-json.mjs Outdated Show resolved Hide resolved
scripts/clean-package-json.mjs Outdated Show resolved Hide resolved
it('handle exist properties required for publishing', async () => {
await t$`node scripts/clean-package-json.mjs`
// to throw if manifest is not correct
const file = createRequire(import.meta.url)(
Copy link
Collaborator

Choose a reason for hiding this comment

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

fs.readFileSync + JSON.parse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

d1

const file = createRequire(import.meta.url)(
path.resolve(tmp, 'package.json')
)
assert.strictEqual(whitelist, Object.keys(file))
Copy link
Collaborator

Choose a reason for hiding this comment

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

assert.equal(pkgJson.name, 'zx')
assert.equal(pkgJson.prettier, undefined)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

d1

@easymikey
Copy link
Contributor Author

I call the tests and my files are deleted. Is this how it should be?

Path = test/vendor-fs.test.js

Screenshot 2024-12-18 at 16 30 32

@antongolub
Copy link
Collaborator

I call the tests and my files are deleted. Is this how it should be?

Path = test/vendor-fs.test.js

Screenshot 2024-12-18 at 16 30 32
$ fnm use 22                               
Using Node v22.10.0
$ node -e "console.log(require('fs').glob)"
[Function: glob]

$ fnm use 20                               
Using Node v20.11.1
$ node -e "console.log(require('fs').glob)"
undefined


const __dirname = path.dirname(new URL(import.meta.url).pathname)
const root = path.resolve(__dirname, '../../')
const whitelist = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

This const is redundant now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting to completely remove the check for fields, since they are in the script?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@easymikey easymikey requested a review from antongolub December 18, 2024 14:07
@easymikey easymikey force-pushed the omit-package-json-field-before-npm-publish branch from c4a0935 to 5e059cd Compare December 18, 2024 14:21
Copy link
Collaborator

@antongolub antongolub left a comment

Choose a reason for hiding this comment

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

lgtm. Thanks!

@antongolub antongolub merged commit c8ca866 into google:main Dec 18, 2024
21 checks passed
@antongolub antongolub added the ossln24 OSS Library Night 2024 label Dec 18, 2024
@easymikey easymikey deleted the omit-package-json-field-before-npm-publish branch December 18, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ossln24 OSS Library Night 2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build: omit redundant pkgjson fields on publishing
2 participants