Skip to content

Commit

Permalink
fix(windows): fix windows for real, hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Apr 17, 2023
1 parent 871f9ae commit 7f7746c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
16 changes: 6 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ class Smoker extends createStrictEventEmitterClass() {
try {
const npmPath = await which('npm');
// using #runNpm here would be recursive
const {stdout: version} = await execa(process.execPath, [
npmPath,
'--version',
]);
const {stdout: version} = await execa(npmPath, ['--version']);
debug('(findNpm) Found npm %s at %s', version, npmPath);
this.#npmPath = npmPath;
this.emit(FIND_NPM_OK, npmPath);
Expand Down Expand Up @@ -384,7 +381,7 @@ class Smoker extends createStrictEventEmitterClass() {
let proc;

try {
proc = execa(process.execPath, [npmPath, ...args], opts);
proc = execa(npmPath, args, opts);
} catch (err) {
this.emit(RUN_NPM_FAILED, /** @type {execa.ExecaError} */ (err));
throw err;
Expand All @@ -406,11 +403,10 @@ class Smoker extends createStrictEventEmitterClass() {
this.emit(RUN_NPM_OK, {command, options, value});
return value;
} catch (e) {
error = /** @type {execa.ExecaError & NodeJS.ErrnoException} */ (e);
if (error.code === 'ENOENT') {
throw new Error(`Could not find "node" at ${process.execPath}`);
}
this.emit(RUN_NPM_FAILED, error);
this.emit(
RUN_NPM_FAILED,
/** @type {execa.ExecaError & NodeJS.ErrnoException} */ (e)
);
throw error;
}
}
Expand Down
39 changes: 13 additions & 26 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ describe('midnight-smoker', function () {

it('should append the "--workspace" flag to "npm pack"', async function () {
await smoker.pack();
expect(mocks.execa, 'was called with', process.execPath, [
MOCK_NPM,
expect(mocks.execa, 'was called with', MOCK_NPM, [
'pack',
'--json',
`--pack-destination=${MOCK_TMPDIR}`,
Expand All @@ -352,8 +351,7 @@ describe('midnight-smoker', function () {

it('should append the "--workspaces" flag to "npm pack"', async function () {
await smoker.pack();
expect(mocks.execa, 'was called with', process.execPath, [
MOCK_NPM,
expect(mocks.execa, 'was called with', MOCK_NPM, [
'pack',
'--json',
`--pack-destination=${MOCK_TMPDIR}`,
Expand All @@ -372,8 +370,7 @@ describe('midnight-smoker', function () {

it('should append the "--include-workspace-root" flag to "npm pack"', async function () {
await smoker.pack();
expect(mocks.execa, 'was called with', process.execPath, [
MOCK_NPM,
expect(mocks.execa, 'was called with', MOCK_NPM, [
'pack',
'--json',
`--pack-destination=${MOCK_TMPDIR}`,
Expand Down Expand Up @@ -483,9 +480,8 @@ describe('midnight-smoker', function () {
it('should execute "npm install" with a list of tarball filepaths', async function () {
await smoker.install(packItems);
expect(mocks.execa, 'to have a call satisfying', [
process.execPath,
MOCK_NPM,
[
MOCK_NPM,
'install',
'--global-style',
...packItems.map((item) => item.tarballFilepath),
Expand Down Expand Up @@ -674,17 +670,9 @@ describe('midnight-smoker', function () {
it('should call "npm run-script" within each "installPath" in "packItems"', async function () {
await smoker.runScripts(packItems);
expect(mocks.execa, 'to have calls satisfying', [
[process.execPath, [MOCK_NPM, '--version']],
[
process.execPath,
[MOCK_NPM, 'run-script', 'foo'],
{cwd: packItems[0].installPath},
],
[
process.execPath,
[MOCK_NPM, 'run-script', 'foo'],
{cwd: packItems[1].installPath},
],
[MOCK_NPM, ['--version']],
[MOCK_NPM, ['run-script', 'foo'], {cwd: packItems[0].installPath}],
[MOCK_NPM, ['run-script', 'foo'], {cwd: packItems[1].installPath}],
]);
});

Expand Down Expand Up @@ -740,11 +728,10 @@ describe('midnight-smoker', function () {
it('should pack, install, and run scripts', async function () {
await smoke('foo');
expect(mocks.execa, 'to have calls satisfying', [
[process.execPath, [MOCK_NPM, '--version']],
[MOCK_NPM, ['--version']],
[
process.execPath,
MOCK_NPM,
[
MOCK_NPM,
'pack',
'--json',
`--pack-destination=${MOCK_TMPDIR}`,
Expand All @@ -753,13 +740,13 @@ describe('midnight-smoker', function () {
{},
],
[
process.execPath,
[MOCK_NPM, 'install', '--global-style', `${MOCK_TMPDIR}/tarball.tgz`],
MOCK_NPM,
['install', '--global-style', `${MOCK_TMPDIR}/tarball.tgz`],
{cwd: MOCK_TMPDIR},
],
[
process.execPath,
[MOCK_NPM, 'run-script', 'foo'],
MOCK_NPM,
['run-script', 'foo'],
{cwd: `${MOCK_TMPDIR}/node_modules/bar`},
],
]);
Expand Down

0 comments on commit 7f7746c

Please sign in to comment.