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

Use mem-fs-editor fromBasePath #1517

Merged
merged 3 commits into from
May 24, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18.x]
node-version: [18.17.x]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.x]
node-version: [18.17.x]

steps:
- name: Checkout yeoman-test
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"json-schema": "^0.4.0",
"latest-version": "^7.0.0",
"lodash-es": "^4.17.21",
"mem-fs-editor": "^11.0.0",
"mem-fs-editor": "^11.0.1",
"minimist": "^1.2.8",
"read-package-up": "^11.0.0",
"semver": "^7.5.4",
Expand Down
18 changes: 9 additions & 9 deletions src/actions/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export class FsMixin {
this: BaseGenerator,
...args: OverloadParameters<MemFsEditor['copy']>
): OverloadReturnType<MemFsEditor['copy']> {
const [from, to, options = {}, ...remaining] = args;
options.fromBasePath = options.fromBasePath ?? this.templatePath();
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
return this.fs.copy(
...applyToFirstAndSecondStringArg(this.templatePath.bind(this), this.destinationPath.bind(this), args),
);
return this.fs.copy(from, this.destinationPath(to), options, ...remaining);
}

/**
Expand Down Expand Up @@ -175,10 +175,10 @@ export class FsMixin {
this: BaseGenerator,
...args: OverloadParameters<MemFsEditor['copy']>
): OverloadReturnType<MemFsEditor['copy']> {
const [from, to, options = {}, ...remaining] = args;
options.fromBasePath = options.fromBasePath ?? this.destinationPath();
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
return this.fs.copy(
...applyToFirstAndSecondStringArg(this.destinationPath.bind(this), this.destinationPath.bind(this), args),
);
return this.fs.copy(from, this.destinationPath(to), options, ...remaining);
}

/**
Expand All @@ -190,10 +190,10 @@ export class FsMixin {
this: BaseGenerator,
...args: OverloadParameters<MemFsEditor['move']>
): OverloadReturnType<MemFsEditor['move']> {
const [from, to, options = {}, ...remaining] = args;
options.fromBasePath = options.fromBasePath ?? this.destinationPath();
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
return this.fs.move(
...applyToFirstAndSecondStringArg(this.destinationPath.bind(this), this.destinationPath.bind(this), args),
);
return this.fs.move(from, this.destinationPath(to), options, ...remaining);
}

/**
Expand Down
28 changes: 18 additions & 10 deletions test/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const ARG_COPYSETTINGS = 4;

type FSOpResult = {
name: string;
first: string;
first?: string;
second?: string;
fromBasePath?: string;
dest: string;
returnsUndefined?: boolean;
};
Expand All @@ -32,8 +33,8 @@ testResults = testResults.concat([
{ name: 'readTemplate', first: 'templatePath', dest: 'read' },
{
name: 'copyTemplate',
first: 'templatePath',
second: 'destinationPath',
fromBasePath: 'templatePath',
dest: 'copy',
},
{
Expand All @@ -52,14 +53,14 @@ testResults = testResults.concat([
{ name: 'deleteDestination', first: 'destinationPath', dest: 'delete' },
{
name: 'copyDestination',
first: 'destinationPath',
second: 'destinationPath',
fromBasePath: 'destinationPath',
dest: 'copy',
},
{
name: 'moveDestination',
first: 'destinationPath',
second: 'destinationPath',
fromBasePath: 'destinationPath',
dest: 'move',
},
{ name: 'existsDestination', first: 'destinationPath', dest: 'exists' },
Expand Down Expand Up @@ -137,21 +138,21 @@ describe('generators.Base (actions/fs)', () => {
for (const operation of testResults) {
const passedArg1 = randomString();
const passedArg2 = randomString();
const passedArg3 = {};
const passedArg3: any = {};
const passedArg4 = { foo: 'bar' };

// eslint-disable-next-line @typescript-eslint/no-loop-func
describe(`#${operation.name}`, () => {
let returnValue: any;
let expectedReturn: string | undefined;
let firstArgumentHandler: SinonStub;
let firstArgumentHandler: SinonStub | undefined;
let secondArgumentHandler: SinonStub;

beforeEach(async function () {
returnValue = await this.base[operation.name](passedArg1, passedArg2, passedArg3, passedArg4);

expectedReturn = operation.returnsUndefined ? undefined : returns[operation.dest];
firstArgumentHandler = this.base[operation.first];
firstArgumentHandler = operation.first ? this.base[operation.first] : undefined;
if (operation.second !== undefined && operation.second !== null) {
secondArgumentHandler = this.base[operation.second];
}
Expand All @@ -166,7 +167,9 @@ describe('generators.Base (actions/fs)', () => {
});

it('handles the first parameter', () => {
assert.equal(firstArgumentHandler.getCall(0).args[0], passedArg1);
if (firstArgumentHandler) {
assert.equal(firstArgumentHandler.getCall(0).args[0], passedArg1);
}
});

it('handles the second parameter', () => {
Expand All @@ -175,8 +178,10 @@ describe('generators.Base (actions/fs)', () => {
assert.equal(secondArgumentHandler.getCall(1).args[0], passedArg2);
} else if (operation.second) {
assert(secondArgumentHandler.calledOnce);
assert(firstArgumentHandler.calledOnce);
assert.equal(secondArgumentHandler.getCall(0).args[0], passedArg2);
if (firstArgumentHandler) {
assert(firstArgumentHandler.calledOnce);
}
}
});

Expand All @@ -185,7 +190,7 @@ describe('generators.Base (actions/fs)', () => {
assert(destCall.calledOnce);
const call = destCall.getCall(0);
// First argument should be the trated first arguments
assert.equal(call.args[0], baseReturns[operation.first]);
assert.equal(call.args[0], operation.first ? baseReturns[operation.first] : passedArg1);

// Second argument should be the trated first arguments
if (operation.second) {
Expand All @@ -196,6 +201,9 @@ describe('generators.Base (actions/fs)', () => {

assert.equal(call.args[2], passedArg3);
assert.equal(call.args[3].foo, passedArg4.foo);
if (operation.fromBasePath) {
assert.equal(call.args[2].fromBasePath, baseReturns[operation.fromBasePath]);
}
});
});
}
Expand Down
Loading