Skip to content

Commit

Permalink
support execa esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden authored and kellyselden committed Nov 6, 2023
1 parent 7ee06d2 commit 4dcad3b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/get-start-and-end-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const path = require('path');
const utils = require('./utils');
const execa = require('execa');
const getTimes = require('boilerplate-update/src/get-times');
const getVersionAsOf = require('boilerplate-update/src/get-version-as-of');

Expand Down Expand Up @@ -45,7 +44,7 @@ function createProjectFromCache({
options
}) {
return async function createProject(cwd) {
await execa.node(path.join(packageRoot, 'index.js'), [
await utils.execaNode(path.join(packageRoot, 'index.js'), [
options.projectName,
'--scripts-version',
options.reactScriptsVersion
Expand All @@ -64,8 +63,10 @@ function createProjectFromRemote({
options
}) {
return async function createProject(cwd) {
let execa = await import('execa');

// create-react-app doesn't work well with async npx
utils.npxSync([`create-react-app@${options.packageVersion}`, options.projectName, '--scripts-version', options.reactScriptsVersion], { cwd });
utils.npxSync.call(execa, [`create-react-app@${options.packageVersion}`, options.projectName, '--scripts-version', options.reactScriptsVersion], { cwd });

return await postCreateProject({
cwd,
Expand Down
3 changes: 1 addition & 2 deletions src/run-sync.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const execa = require('execa');
const debug = require('./debug');

module.exports = function runSync() {
debug(...arguments);
let { stdout } = execa.sync(...arguments);
let { stdout } = this.execaSync(...arguments);
debug(stdout);
return stdout;
};
8 changes: 7 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ module.exports.npxSync = function npxSync(args, options) {
// ...options
// });

return require('./run-sync')('node', [path.join(path.dirname(require.resolve('npm')), 'bin/npx-cli.js'), ...args], options);
return require('./run-sync').call(this, 'node', [path.join(path.dirname(require.resolve('npm')), 'bin/npx-cli.js'), ...args], options);
};

module.exports.execaNode = async function execaNode() {
let { execaNode } = await import('execa');

return execaNode(...arguments);
};
3 changes: 1 addition & 2 deletions test/unit/get-start-and-end-commands-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const sinon = require('sinon');
const path = require('path');
const _getStartAndEndCommands = require('../../src/get-start-and-end-commands');
const utils = require('../../src/utils');
const execa = require('execa');

const projectName = 'my-custom-app';
const createReactAppStartVersion = '0.0.1';
Expand All @@ -29,7 +28,7 @@ describe(_getStartAndEndCommands, function() {

beforeEach(function() {
npxSyncStub = sinon.stub(utils, 'npxSync');
execaNodeStub = sinon.stub(execa, 'node').resolves();
execaNodeStub = sinon.stub(utils, 'execaNode').resolves();
ejectStub = sinon.stub(utils, 'eject').resolves();
});

Expand Down

0 comments on commit 4dcad3b

Please sign in to comment.