diff --git a/lib/cli.js b/lib/cli.js index c5d54f56..952e5f31 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,9 +1,10 @@ "use strict"; import bag from 'bagofcli'; import p from 'path'; +import { fileURLToPath } from 'url'; import RTK from './rtk.js'; -const DIRNAME = p.dirname(import.meta.url).replace('file://', ''); +const DIRNAME = p.dirname(fileURLToPath(import.meta.url)); function _release(args) { @@ -42,4 +43,4 @@ const exports = { export { exports as default -}; \ No newline at end of file +}; diff --git a/test/cli.js b/test/cli.js index a68f0726..d3fdc934 100644 --- a/test/cli.js +++ b/test/cli.js @@ -3,6 +3,8 @@ import RTK from '../lib/rtk.js'; import bag from 'bagofcli'; import cli from '../lib/cli.js'; +import p from 'path'; +import { fileURLToPath } from 'url'; import referee from '@sinonjs/referee'; import sinon from 'sinon'; const assert = referee.assert; @@ -18,6 +20,21 @@ describe('cli - exec', function() { sinon.stub(bag, 'command').value(mockCommand); cli.exec(); }); + + it('should pass a native filesystem base path to bagofcli', function (done) { + const expectedBase = p.dirname(fileURLToPath(new URL('../lib/cli.js', import.meta.url))); + const mockCommand = function (base, actions) { + assert.equals(base, expectedBase); + assert.equals(base.startsWith('file:'), false); + if (process.platform === 'win32') { + assert.equals(/^[/\\][A-Za-z]:/.test(base), false); + } + assert.isFunction(actions.commands.release.action); + done(); + }; + sinon.stub(bag, 'command').value(mockCommand); + cli.exec(); + }); }); describe('cli - release', function() { @@ -53,4 +70,4 @@ describe('cli - release', function() { }); cli.exec(); }); -}); \ No newline at end of file +});