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

Fix leading and trailing spaces in source patterns #23

Merged
merged 1 commit into from
Dec 31, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## v1.8.1
- Fix leading and trailing spaces in source patterns ([#22](https://github.com/qetza/replacetokens/issues/22)).

## v1.8.0
- Add exit code to CLI in case of error.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qetza/replacetokens",
"version": "1.8.0",
"version": "1.8.1",
"description": "replace tokens in files",
"author": "Guillaume ROUCHON",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/bin/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function run() {
// parse arguments
var argv = await yargs(process.argv.slice(2))
.scriptName('replacetokens')
.version('1.8.0')
.version('1.8.1')
.usage('$0 [args]')
.help()
.options({
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ function parseSources(sources: readonly string[]): readonly InputPattern[] {
let patterns: InputPattern[] = [];

sources.forEach(source => {
const parts = source.split('=>');
const parts = source.split('=>').map(i => i.trim());
const pattern: InputPattern = {
inputHasWildcard: false,
inputPatterns: parts[0].trim().split(';'),
inputPatterns: parts[0].split(';').map(i => i.trim()),
isOutputRelative: false,
outputPattern: undefined
};
Expand All @@ -379,7 +379,7 @@ function parseSources(sources: readonly string[]): readonly InputPattern[] {

if (parts.length > 1) {
// source has output
pattern.outputPattern = normalizePath(parts[1].trim());
pattern.outputPattern = normalizePath(parts[1]);
pattern.isOutputRelative = !path.isAbsolute(pattern.outputPattern);
}

Expand Down
18 changes: 17 additions & 1 deletion tests/replacetokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ describe('replaceTokens', () => {
await expectFileToEqual(input, 'default.expected.json');
});

it('input path with leading and trailing spaces', async () => {
// arrange
const input = await copyData('default.json', 'default1.json');
spyOnConsole();

// act
const result = await replaceTokens(
normalizeSources(` ${input} `),
getVariableCallback({ var1: 'var1_value', var2: 'var2_value' })
);

// assert
expectCountersToEqual(result, 0, 1, 2, 2, 0);
await expectFileToEqual(input, 'default.expected.json');
});

it('input path with wildcard', async () => {
// arrange
const input1 = await copyData('default.json', 'default1.json');
Expand Down Expand Up @@ -155,7 +171,7 @@ describe('replaceTokens', () => {

// act
const result = await replaceTokens(
normalizeSources(`${path.join(tmp, '*.json')};!${input2}`),
normalizeSources(` ${path.join(tmp, '*.json')} ; !${input2} `),
getVariableCallback({
var1: 'var1_value',
var2: 'var2_value'
Expand Down
Loading