Skip to content

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

Merged
antongolub merged 6 commits intogoogle:mainfrom
easymikey:omit-package-json-field-before-npm-publish
Dec 18, 2024
Merged

feat: create script for omit package.json fields before publish#1005
antongolub merged 6 commits intogoogle:mainfrom
easymikey:omit-package-json-field-before-npm-publish

Conversation

@easymikey
Copy link
Copy Markdown
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
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Correct.

Copy link
Copy Markdown
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
Copy Markdown
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
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: omit redundant pkgjson fields on publishing

2 participants