Skip to content

Commit

Permalink
Create Block: Fix support for external templates hosted on npm (#27776)
Browse files Browse the repository at this point in the history
Instead of using @wordpress/lazy-import that sdoesn not work when invoked with `npm init` or `npx`, the idea is to use `npm install --no-save` and a require call
  • Loading branch information
gziolo authored Dec 17, 2020
1 parent 9e74e56 commit 5425353
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/create-block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fix

- Fix support for external templates hosted on npm.

## 1.0.0 (2020-12-17)

### Breaking Changes
Expand Down
11 changes: 3 additions & 8 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ const { readFile } = require( 'fs' ).promises;
const { fromPairs, isObject } = require( 'lodash' );
const { join } = require( 'path' );

/**
* WordPress dependencies
*/
const lazyImport = require( '@wordpress/lazy-import' );

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -98,9 +93,9 @@ const getBlockTemplate = async ( templateName ) => {
info( '' );
info( 'Downloading template files. It might take some time...' );

const { defaultValues = {}, templatesPath } = await lazyImport(
templateName
);
await command( `npm install ${ templateName } --no-save` );

const { defaultValues = {}, templatesPath } = require( templateName );
if ( ! isObject( defaultValues ) || ! templatesPath ) {
throw new Error();
}
Expand Down

0 comments on commit 5425353

Please sign in to comment.