Skip to content

Commit 3a959a7

Browse files
authored
fix(dep): add stringify-package to project source, removing the deprecation warning on npm install (#65)
2 parents bc6f792 + 5fddabf commit 3a959a7

File tree

5 files changed

+76
-13
lines changed

5 files changed

+76
-13
lines changed

lib/stringify-package.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright npm, Inc
3+
4+
Permission to use, copy, modify, and/or distribute this software for any
5+
purpose with or without fee is hereby granted, provided that the above
6+
copyright notice and this permission notice appear in all copies.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
16+
https://github.com/npm/stringify-package/blob/main/LICENSE
17+
*/
18+
19+
'use strict'
20+
21+
module.exports = stringifyPackage
22+
23+
const DEFAULT_INDENT = 2
24+
const CRLF = '\r\n'
25+
const LF = '\n'
26+
27+
function stringifyPackage (data, indent, newline) {
28+
indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT)
29+
const json = JSON.stringify(data, null, indent)
30+
31+
if (newline === CRLF) {
32+
return json.replace(/\n/g, CRLF) + CRLF
33+
}
34+
35+
return json + LF
36+
}

lib/updaters/types/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const stringifyPackage = require('stringify-package')
1+
const stringifyPackage = require('../../stringify-package')
22
const detectIndent = require('detect-indent')
33
const detectNewline = require('detect-newline')
44

package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"find-up": "^5.0.0",
5353
"git-semver-tags": "^4.0.0",
5454
"semver": "^7.1.1",
55-
"stringify-package": "^1.0.1",
5655
"yargs": "^17.0.0"
5756
},
5857
"devDependencies": {

test/stringify-package.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* global describe it */
2+
3+
'use strict'
4+
5+
const stringifyPackage = require('../lib/stringify-package')
6+
7+
require('chai').should()
8+
9+
describe('stringifyPackage()', function () {
10+
const dummy = { name: 'dummy' }
11+
12+
it('with no params uses \\n', function () {
13+
stringifyPackage(dummy).should.match(/\n$/m)
14+
})
15+
16+
it('uses \\n', function () {
17+
stringifyPackage(dummy, 2, '\n').should.match(/\n$/m)
18+
})
19+
20+
it('uses \\r\\n', function () {
21+
stringifyPackage(dummy, 2, '\r\n').should.match(/\r\n$/m)
22+
})
23+
24+
it('with no params uses 2-space indent', function () {
25+
stringifyPackage(dummy).should.match(/^ {2}"name": "dummy"/m)
26+
})
27+
28+
it('uses 2-space indent', function () {
29+
stringifyPackage(dummy, 2, '\n').should.match(/^ {2}"name": "dummy"/m)
30+
})
31+
32+
it('uses 4-space indent', function () {
33+
stringifyPackage(dummy, 4, '\n').should.match(/^ {4}"name": "dummy"/m)
34+
})
35+
36+
it('0 works', function () {
37+
stringifyPackage(dummy, 0).split(/\r\n|\r|\n/).length.should.equal(2)
38+
})
39+
})

0 commit comments

Comments
 (0)