Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
engines:
# Disable path traversal checks for test files (false positives for test fixtures)
# and CLI config loading (intentional behavior)
semgrep:
exclude_paths:
- "**/__tests__/**"
- "**/tests/**"

exclude_paths:
# Ignore test directories for security-focused rules
# Tests legitimately use dynamic paths to load fixtures
- "**/__tests__/**"
- "**/tests/**"
# Node modules should not be analyzed
- "node_modules/**"
- "**/node_modules/**"
2 changes: 1 addition & 1 deletion packages/shipjs-lib/src/lib/util/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function updateVersion({
fileName = 'package.json',
}) {
const filePath = resolve(dir, fileName);
const json = JSON.parse(readFileSync(filePath).toString());
const json = JSON.parse(readFileSync(filePath, 'utf-8'));
json.version = nextVersion;
writeFileSync(filePath, `${JSON.stringify(json, null, 2)}\n`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import path from 'path';

import extractSpecificChangelog from '../extractSpecificChangelog.js';

const shipjsChangelogExample = fs
.readFileSync(path.resolve(__dirname, 'shipjs-changelog.md'))
.toString();

const conventionalChangelogExample = fs
.readFileSync(path.resolve(__dirname, 'conventional-changelog.md'))
.toString();

const lernaChangelogExample = fs
.readFileSync(path.resolve(__dirname, 'lerna-changelog.md'))
.toString();
const shipjsChangelogExample = fs.readFileSync(
path.resolve(__dirname, 'shipjs-changelog.md'),
'utf-8'
);

const conventionalChangelogExample = fs.readFileSync(
path.resolve(__dirname, 'conventional-changelog.md'),
'utf-8'
);

const lernaChangelogExample = fs.readFileSync(
path.resolve(__dirname, 'lerna-changelog.md'),
'utf-8'
);

describe('extractSpecificChangelog', () => {
describe('conventional-changelog', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shipjs/src/helper/dependencyUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function runUpdates(list) {
list.forEach(({ name, packagePath, updates }) => {
print(` package: ${name} (${packagePath}}/package.json)`);
const filePath = resolve(packagePath, 'package.json');
const json = JSON.parse(readFileSync(filePath).toString());
const json = JSON.parse(readFileSync(filePath, 'utf-8'));
Object.keys(updates).forEach((dependencyType) => {
print(` ${dependencyType}:`);
updates[dependencyType].forEach(
Expand All @@ -112,7 +112,7 @@ export function prepareJsons(packageList) {
return packageList.map((packagePath) => ({
packagePath,
json: JSON.parse(
readFileSync(resolve(packagePath, 'package.json')).toString()
readFileSync(resolve(packagePath, 'package.json'), 'utf-8')
),
}));
}
2 changes: 1 addition & 1 deletion packages/shipjs/src/helper/getChangelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { extractSpecificChangelog } from './index.js';
export default function getChangelog({ version, dir }) {
const changelogPath = path.resolve(dir, 'CHANGELOG.md');
try {
const changelog = fs.readFileSync(changelogPath, 'utf-8').toString();
const changelog = fs.readFileSync(changelogPath, 'utf-8');
return extractSpecificChangelog({ changelog, version });
} catch (err) {
if (err.code === 'ENOENT') {
Expand Down
2 changes: 1 addition & 1 deletion packages/shipjs/src/helper/runPrettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import prettier from 'prettier';

export default async function runPrettier({ filePath, dir }) {
const text = fs.readFileSync(filePath).toString();
const text = fs.readFileSync(filePath, 'utf-8');
const options = await prettier.resolveConfig(dir);
const formatted = prettier.format(text, {
...(options || {}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path';

import tempWrite from 'temp-write';

import { parseArgs } from '../../../util/index.js';
import { prepareParams } from '../updateChangelog.js';

const path = require('path');

describe('prepareParams', () => {
it('loads configuration from --config option', async () => {
parseArgs.mockImplementation(jest.requireActual('../../../util').parseArgs);
Expand Down
9 changes: 6 additions & 3 deletions packages/shipjs/src/step/prepare/updateChangelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@
if (args.commitPath) {
gitRawCommitsOpts.path = args.commitPath;
}
const templateContext =
args.context && require(path.resolve(dir, args.context));
args.config = args.config ? require(path.resolve(dir, args.config)) : {};
const templateContext = args.context
? (await import(path.resolve(dir, args.context))).default
: undefined;
args.config = args.config
? (await import(path.resolve(dir, args.config))).default

Check failure on line 133 in packages/shipjs/src/step/prepare/updateChangelog.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/shipjs/src/step/prepare/updateChangelog.js#L133

Detected possible user input going into a `path.join` or `path.resolve` function.
: {};
if (args.preset) {
try {
args.config = merge(
Expand Down
2 changes: 1 addition & 1 deletion packages/shipjs/src/step/setup/addDevDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default ({ dependencies, dir, dryRun }) =>

function usesYarnWorkspace(dir) {
return Boolean(
JSON.parse(fs.readFileSync(path.resolve(dir, 'package.json')).toString())
JSON.parse(fs.readFileSync(path.resolve(dir, 'package.json'), 'utf-8'))
.workspaces
);
}
2 changes: 1 addition & 1 deletion packages/shipjs/src/step/setup/addScriptsToPackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async ({ dir, dryRun }) =>
await runStep({ title: 'Adding scripts to package.json' }, async () => {
if (!dryRun) {
const filePath = path.resolve(dir, 'package.json');
const json = JSON.parse(fs.readFileSync(filePath).toString());
const json = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
json.scripts = json.scripts || {};
json.scripts.release = 'shipjs prepare';
fs.writeFileSync(filePath, `${JSON.stringify(json, null, 2)}\n`);
Expand Down
2 changes: 1 addition & 1 deletion packages/shipjs/src/step/setup/addShipConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default async ({

function checkIfScriptsExist({ dir }) {
const filePath = path.resolve(dir, 'package.json');
const json = JSON.parse(fs.readFileSync(filePath).toString());
const json = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
const { build } = json.scripts || {};
return {
buildExists: Boolean(build),
Expand Down
2 changes: 1 addition & 1 deletion packages/shipjs/src/step/setup/askQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function getMonorepoPackages(dir) {
function getJson(dir, fileName) {
const filePath = path.resolve(dir, fileName);
return fs.existsSync(filePath)
? JSON.parse(fs.readFileSync(filePath).toString())
? JSON.parse(fs.readFileSync(filePath, 'utf-8'))
: {};
}

Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13387,7 +13387,7 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

[email protected], prettier@^2.0.0:
[email protected]:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
Expand All @@ -13397,6 +13397,11 @@ prettier@^1.18.2:
resolved "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

prettier@^2.0.0:
version "2.0.5"
resolved "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==

pretty-error@^2.0.2:
version "2.1.1"
resolved "https://registry.npmjs.org/pretty-error/-/pretty-error-2.1.1.tgz"
Expand Down