Skip to content

Commit

Permalink
fix: Actually make it work, maybe.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-mitchell committed Nov 16, 2024
1 parent 6dd0630 commit 6909204
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 26 deletions.
File renamed without changes.
File renamed without changes.
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Node's require cache in order to create multiple copies
// of the module in order to use it with different configurations.
const registryPlugins = {};
function getChildPlugin(registryName) {
async function getChildPlugin(registryName) {
let plugin = registryPlugins[registryName];
if (!plugin) {
plugin = import(
Expand All @@ -14,15 +14,18 @@ function getChildPlugin(registryName) {
registryPlugins[registryName] = plugin;
}

return plugin;
return await plugin;
}

function createCallbackWrapper(callbackName) {
return async ({ registries, ...pluginConfig }, context) => {
for (const [registryName, childConfig] of Object.entries(
registries || {},
)) {
const callback = getChildPlugin(registryName)[callbackName];
const plugin = await getChildPlugin(registryName);
console.log({ plugin });

const callback = plugin[callbackName];
if (!callback) {
return;
}
Expand Down Expand Up @@ -57,9 +60,7 @@ function createCallbackWrapper(callbackName) {
};
}

const callbackNames = ['verify', 'prepare', 'publish', 'success', 'fail'];

module.exports = Object.assign(
{},
...callbackNames.map(name => ({ [name]: createCallbackWrapper(name) })),
);
export const addChannel = createCallbackWrapper('addChannel');
export const prepare = createCallbackWrapper('prepare');
export const publish = createCallbackWrapper('publish');
export const verifyConditions = createCallbackWrapper('verifyConditions');
53 changes: 37 additions & 16 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
const { verify, prepare, publish, success, fail } = require('./index');
import { mkdtemp, rmdir } from 'fs/promises';
import { addChannel, prepare, publish, verifyConditions } from './index.js';
import * as underlyingPlugin from '@semantic-release/npm';

const pluginConfig = { registries: { github: {}, public: {} } };
let workingDirectory;

describe('verify', () => {
beforeAll(async () => {
workingDirectory = await mkdtemp('.');
});

afterAll(async () => {
await rmdir(workingDirectory, { recursive: true });
});

const createPluginConfig = () => ({
registries: { github: {}, public: {} },
npmPublish: false,
});

const createContext = () => ({
logger: console,
env: {},
nextRelease: { version: '1.0' },
cwd: workingDirectory,
});

describe('addChannel', () => {
it('does not crash', async () => {
await verify(pluginConfig, {});
await addChannel(createPluginConfig, createContext);
});
});

describe('prepare', () => {
it('does not crash', async () => {
await prepare(pluginConfig, {});
describe('underlying plugin endpoints', () => {
it('has the expected set of keys', () => {
expect(new Set(Object.keys(underlyingPlugin))).toEqual(
new Set(['addChannel', 'prepare', 'publish', 'verifyConditions']),
);
});
});

// We skip this one because it's not worth
// setting up sufficient scaffolding to actually
// try publishing a package.
describe.skip('publish', () => {
describe('prepare', () => {
it('does not crash', async () => {
await publish(pluginConfig, {});
await prepare(createPluginConfig, createContext);
});
});

describe('success', () => {
describe('publish', () => {
it('does not crash', async () => {
await success(pluginConfig, {});
await publish(createPluginConfig, createContext);
});
});

describe('fail', () => {
describe('verifyConditions', () => {
it('does not crash', async () => {
await fail(pluginConfig, {});
await verifyConditions(createPluginConfig, createContext);
});
});
File renamed without changes.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"repository": "https://github.com/amanda-mitchell/semantic-release-npm-multiple",
"author": "Amanda Mitchell <[email protected]>",
"license": "MIT",
"type": "module",
"files": [
"index.js"
],
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion release.config.js → release.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
[require('./index'), { registries: { github: {}, public: {} } }],
[require('./index.js'), { registries: { github: {}, public: {} } }],
'@semantic-release/github',
],
};

0 comments on commit 6909204

Please sign in to comment.