diff --git a/commitlint.config.js b/commitlint.config.cjs similarity index 100% rename from commitlint.config.js rename to commitlint.config.cjs diff --git a/husky.config.js b/husky.config.cjs similarity index 100% rename from husky.config.js rename to husky.config.cjs diff --git a/index.js b/index.js index 3f84a2b..4b99299 100644 --- a/index.js +++ b/index.js @@ -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( @@ -14,7 +14,7 @@ function getChildPlugin(registryName) { registryPlugins[registryName] = plugin; } - return plugin; + return await plugin; } function createCallbackWrapper(callbackName) { @@ -22,7 +22,10 @@ function createCallbackWrapper(callbackName) { 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; } @@ -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'); diff --git a/index.test.js b/index.test.js index 05c0f72..403408e 100644 --- a/index.test.js +++ b/index.test.js @@ -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); }); }); diff --git a/lint-staged.config.js b/lint-staged.config.cjs similarity index 100% rename from lint-staged.config.js rename to lint-staged.config.cjs diff --git a/package.json b/package.json index b747d1a..3558139 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "repository": "https://github.com/amanda-mitchell/semantic-release-npm-multiple", "author": "Amanda Mitchell ", "license": "MIT", + "type": "module", "files": [ "index.js" ], diff --git a/prettier.config.js b/prettier.config.cjs similarity index 100% rename from prettier.config.js rename to prettier.config.cjs diff --git a/release.config.js b/release.config.cjs similarity index 71% rename from release.config.js rename to release.config.cjs index 060104c..467fb95 100644 --- a/release.config.js +++ b/release.config.cjs @@ -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', ], };