Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `npm init` now has a `type` prompt, and sorts the entries the created packages differently
  • Loading branch information
wraithgar committed Dec 6, 2024
1 parent 2af31dd commit d463a6f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
12 changes: 9 additions & 3 deletions node_modules/init-package-json/lib/default-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,17 @@ if (!package.scripts) {

if (!package.repository) {
exports.repository = async () => {
const gconf = await fs.readFile('.git/config', 'utf8').catch(() => '')
const gitConfigPath = path.resolve(dirname, '.git', 'config')
const gconf = await fs.readFile(gitConfigPath, 'utf8').catch(() => '')
const lines = gconf.split(/\r?\n/)

let url
const i = lines.indexOf('[remote "origin"]')

if (i !== -1) {
url = gconf[i + 1]
url = lines[i + 1]
if (!url.match(/^\s*url =/)) {
url = gconf[i + 2]
url = lines[i + 2]
}
if (!url.match(/^\s*url =/)) {
url = null
Expand Down Expand Up @@ -260,3 +261,8 @@ exports.license = yes ? license : prompt('license', license, (data) => {
const errors = (its.errors || []).concat(its.warnings || [])
return invalid(`Sorry, ${errors.join(' and ')}.`)
})

const type = package.type || getConfig('type') || 'commonjs'
exports.type = yes ? type : prompt('type', type, (data) => {
return data
})
2 changes: 1 addition & 1 deletion node_modules/init-package-json/lib/init-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function init (dir,
return
}

await pkg.save()
await pkg.save({ sort: true })
return pkg.content
}

Expand Down
12 changes: 6 additions & 6 deletions node_modules/init-package-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "init-package-json",
"version": "7.0.1",
"version": "8.0.0",
"main": "lib/init-package-json.js",
"scripts": {
"test": "tap",
Expand All @@ -20,7 +20,7 @@
"license": "ISC",
"description": "A node module to get your node module started",
"dependencies": {
"@npmcli/package-json": "^6.0.0",
"@npmcli/package-json": "^6.1.0",
"npm-package-arg": "^12.0.0",
"promzard": "^2.0.0",
"read": "^4.0.0",
Expand All @@ -29,13 +29,13 @@
"validate-npm-package-name": "^6.0.0"
},
"devDependencies": {
"@npmcli/config": "^8.2.0",
"@npmcli/config": "^9.0.0",
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.23.3",
"@npmcli/template-oss": "4.23.4",
"tap": "^16.0.1"
},
"engines": {
"node": "^18.17.0 || >=20.5.0"
"node": "^20.17.0 || >=22.9.0"
},
"tap": {
"test-ignore": "fixtures/",
Expand All @@ -61,7 +61,7 @@
],
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.23.3",
"version": "4.23.4",
"publish": true
}
}
12 changes: 6 additions & 6 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"graceful-fs": "^4.2.11",
"hosted-git-info": "^8.0.2",
"ini": "^5.0.0",
"init-package-json": "^7.0.1",
"init-package-json": "^8.0.0",
"is-cidr": "^5.1.0",
"json-parse-even-better-errors": "^4.0.0",
"libnpmaccess": "^10.0.0-pre.0",
Expand Down Expand Up @@ -9195,13 +9195,13 @@
}
},
"node_modules/init-package-json": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/init-package-json/-/init-package-json-7.0.1.tgz",
"integrity": "sha512-8KZtk/53ReI2T2f6z2hl5ql6xKLjDexNw7DUqTdR8f+Mo8WZmBjjkH6DrTfBjmW0j3Tqx+j3t8creN0O890+0A==",
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/init-package-json/-/init-package-json-8.0.0.tgz",
"integrity": "sha512-zKgxfaGt6Zzi8VBSInOK0CYDigA9gzDCWPnSzGIoUlTU/5w7qIyi+6MyJYX96mMlxDGrIR85FhQszVyodYfB9g==",
"inBundle": true,
"license": "ISC",
"dependencies": {
"@npmcli/package-json": "^6.0.0",
"@npmcli/package-json": "^6.1.0",
"npm-package-arg": "^12.0.0",
"promzard": "^2.0.0",
"read": "^4.0.0",
Expand All @@ -9210,7 +9210,7 @@
"validate-npm-package-name": "^6.0.0"
},
"engines": {
"node": "^18.17.0 || >=20.5.0"
"node": "^20.17.0 || >=22.9.0"
}
},
"node_modules/internal-slot": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"graceful-fs": "^4.2.11",
"hosted-git-info": "^8.0.2",
"ini": "^5.0.0",
"init-package-json": "^7.0.1",
"init-package-json": "^8.0.0",
"is-cidr": "^5.1.0",
"json-parse-even-better-errors": "^4.0.0",
"libnpmaccess": "^10.0.0-pre.0",
Expand Down
9 changes: 9 additions & 0 deletions smoke-tests/tap-snapshots/test/index.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Wrote to {NPM}/{TESTDIR}/project/package.json:
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"description": ""
}
`
Expand Down Expand Up @@ -171,6 +172,7 @@ Object {
"scripts": Object {
"test": "echo /"Error: no test specified/" && exit 1",
},
"type": "commonjs",
"version": "1.0.0",
}
`
Expand Down Expand Up @@ -223,6 +225,7 @@ Object {
"scripts": Object {
"test": "echo /"Error: no test specified/" && exit 1",
},
"type": "commonjs",
"version": "1.0.0",
}
`
Expand Down Expand Up @@ -253,6 +256,7 @@ Object {
"hello": "echo Hello",
"test": "echo /"Error: no test specified/" && exit 1",
},
"type": "commonjs",
"version": "1.0.0",
}
`
Expand All @@ -277,6 +281,7 @@ Object {
"LC_ALL=sk",
],
},
"type": "commonjs",
"version": "1.0.0",
}
`
Expand Down Expand Up @@ -305,6 +310,7 @@ exports[`test/index.js TAP basic npm pkg > should print package.json contents 1`
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"description": "",
"dependencies": {
"abbrev": "^1.0.4"
Expand Down Expand Up @@ -335,6 +341,7 @@ Object {
"hello": "echo Hello",
"test": "echo /"Error: no test specified/" && exit 1",
},
"type": "commonjs",
"version": "1.0.0",
}
`
Expand Down Expand Up @@ -392,6 +399,7 @@ Object {
"hello": "echo Hello",
"test": "echo /"Error: no test specified/" && exit 1",
},
"type": "commonjs",
"version": "1.0.0",
}
`
Expand Down Expand Up @@ -452,6 +460,7 @@ Object {
"hello": "echo Hello",
"test": "echo /"Error: no test specified/" && exit 1",
},
"type": "commonjs",
"version": "1.0.0",
}
`
Expand Down

0 comments on commit d463a6f

Please sign in to comment.