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 incorrect behavior on package rename #135

Merged
merged 1 commit into from
Aug 10, 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
6 changes: 2 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module.exports = {
env: {
browser: false,
commonjs: true,
es2021: true
es2021: true,
node: true
},
extends: [
"eslint:recommended",
"plugin:node/recommended"
],
overrides: [],
parserOptions: {
Expand All @@ -18,8 +18,6 @@ module.exports = {
asyncArrow: "always",
named: "never"
}],
"prettier/prettier": "off",
"ember-suave/lines-between-object-propertiess": "off",
"no-empty": "off",
"no-unused-vars": [ "error", {
argsIgnorePattern: "^_"
Expand Down
52 changes: 52 additions & 0 deletions spec/publish-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ describe('apm publish', () => {
spyOn(Publish.prototype, 'packageExists').andCallFake(() => {
return Promise.resolve(true);
});

const packageToPublish = temp.mkdirSync('apm-test-package-');
const metadata = {
name: 'test',
Expand Down Expand Up @@ -243,4 +244,55 @@ describe('apm publish', () => {
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});
});

it('publishes successfully when the package exists and is being renamed', () => {
spyOn(Publish.prototype, 'packageExists').andCallFake((name) => {
// If we're renaming the package, we need to ask the API if the package's
// _old_ name exists. This mock will simulate what the API would say if
// we mistakenly ask it if the _new_ name exists.
return name === 'test';
});
let publishPackageSpy = spyOn(Publish.prototype, 'publishPackage').andCallThrough();
let registerPackageSpy = spyOn(Publish.prototype, 'registerPackage').andCallThrough();

const packageToPublish = temp.mkdirSync('apm-test-package-');
const metadata = {
name: 'test',
version: '1.0.0',
"repository": {
"type": "git",
"url": "https://github.com/pulsar-edit/foo"
},
engines: {
atom: '1'
},
dependencies: {
foo: '^5'
},
devDependencies: {
abc: 'git://github.com/user/project.git',
abcd: 'latest',
}
};
fs.writeFileSync(path.join(packageToPublish, 'package.json'), JSON.stringify(metadata));
process.chdir(packageToPublish);

childProcess.execSync('git init', { cwd: packageToPublish });
childProcess.execSync('git remote add origin https://github.com/pulsar-edit/foo', { cwd: packageToPublish });

const callback = jasmine.createSpy('callback');
apm.run(['publish', 'patch', '--rename', 'test-renamed'], callback);
waitsFor('waiting for publish to complete', 600000, () => callback.callCount === 1);
runs(() => {
expect(registerPackageSpy.calls.length).toBe(0);
expect(publishPackageSpy.calls.length).toBe(1);
expect(
publishPackageSpy.mostRecentCall?.args?.[2]?.rename
).toBe('test-renamed');
expect(requests.length).toBe(1);
expect(callback.mostRecentCall.args[0]).toBeUndefined();
});

});

});
5 changes: 4 additions & 1 deletion src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,10 @@ have published it.\

let doesPackageExist;
try {
doesPackageExist = await this.packageExists(pack.name);
// If `originalName` is defined, it means we're renaming this package.
// We must therefore check if the package's _old_ name exists, not its
// _new_ name.
doesPackageExist = await this.packageExists(originalName ?? pack.name);
} catch(error) {
return error;
}
Expand Down
Loading