-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve incosistency in directory option in JS vs CLI usage #355
Comments
Metalsmith.directory
is defaulted to process.cwd()
. In the JS approach there is no default and __dirname
needs to be passed explicitly. Solution:A) force specifying a directory
option in metalsmith.json
(breaking) or B) Make __dirname
also the default for the JS solution (backwards-compatible)
To resolve the inconsistency, |
See https://replit.com/@webketje/Metalsmith-CLI-dirpath-tests which does multiple CLI tests from different [
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests',
name: 'Repo root (default)',
success: true
},
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests',
name: 'Next - Repo root (default)',
success: true
},
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests',
name: 'Repo root (absolute config path)',
success: true
},
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests',
name: 'Next - Repo root (absolute config path)',
success: true
},
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests/src',
name: 'Repo subdir',
error: 'Command failed: node ../bin/metalsmith -c ../metalsmith.json'
},
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests/src',
name: 'Next - Repo subdir',
success: true
},
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests',
name: 'Repo subdir (absolute config path)',
success: true
},
{
chdir: '/home/runner/Metalsmith-CLI-dirpath-tests',
name: 'Next - Repo subdir (absolute config path)',
success: true
},
{
chdir: '/home/runner',
name: 'Outside repo',
error: 'Command failed: node ./Metalsmith-CLI-dirpath-tests/bin/metalsmith -c ./Metalsmith-CLI-dirpath-tests/metalsmith.json'
},
{ chdir: '/home/runner', name: 'Next - Outside repo', success: true }
] As you can see with Metalsmith 2.3, running the metalsmith bin from a path other than the repo root fails. It fails because it resolves local plugins and |
It looks interesting to do some default path resolution in both the CLI as the JS API, especially given the unavailability of __dirname in ES modules, see https://techsparx.com/nodejs/esnext/dirname-es-modules.html |
There is an inconsistency in the metalsmith CLI vs JS approach: in the CLI
Metalsmith.directory
is defaulted toprocess.cwd()
. In the JS approach there is no default and__dirname
needs to be passed explicitly. Solution:A) force specifying adirectory
option inmetalsmith.json
(breaking) or B) Make__dirname
also the default for the JS solution (backwards-compatible)The text was updated successfully, but these errors were encountered: