Skip to content
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

Consider using node-glob instead of shell expansion #35

Closed
christiannaths opened this issue Jul 21, 2019 · 5 comments · Fixed by #38
Closed

Consider using node-glob instead of shell expansion #35

christiannaths opened this issue Jul 21, 2019 · 5 comments · Fixed by #38
Labels
bug Something isn't working released

Comments

@christiannaths
Copy link

First, awesome lib! Using this for our internal developer's wiki and it's such a nice & simple solution.

Context

My package.json

{
 "scripts": {
    "build": "embedme **/*.md"
  },
  "devDependencies": {
    "embedme": "^1.15.0",
  }
}

Problem

Using shell expansion for globbing leads to inconsistencies across platforms.

Because npm is using /bin/sh, and I'm on OSX, I'm stuck with Bash 3.x, and globbing doesn't work the same as it does my usual shell (zsh). Results may vary among other devs on my team.

So given the context above, when I run npm run build a file like foo/bar/baz/doc.md will not be included. However, that file will be included for developer whose /binb/sh points to Bash 4.x, for example.

Proposed Solution

Many node libraries use node-glob to solve this. The downside is that a user must quote glob patterns in their scripts entries, however this pattern is so common that it's easy to find this solution when things don't work as expected.

Workarounds

Currently, I'm handling this (rather naively) with this:

// scripts/build.js

const glob = require('glob');
const { execSync } = require('child_process');

const PATTERN = '**/*.md';

function init(pattern) {
  glob(pattern, {}, function(error, files) {
    const cmd = ['embedme', ...files].join(' ');
    execSync(cmd, { stdio: 'inherit' });
  });
}

init(PATTERN);
{
  "scripts": {
    "build": "node scripts/build.js"
  },
  "devDependencies": {
    "embedme": "^1.15.0",
    "glob": "^7.1.4"
  }
}

I'd be more than happy to contribute with a PR, but I wanted to raise this for discussion first.

@zakhenry
Copy link
Owner

zakhenry commented Jul 21, 2019 via email

@zakhenry zakhenry added the bug Something isn't working label Jul 21, 2019
@christiannaths
Copy link
Author

Yeah, good call on it being a breaking change. I think the idea to pick a strategy based on quoted/non-quoted glob patterns makes perfect sense. I'll try to find some time this week to put a PR in for this 👍

@caesarcc
Copy link
Contributor

caesarcc commented Jul 22, 2019

Hy dear, I'm trying to use npx embedme wiki/*.md, but it's not working for me. I'm getting "File wiki/*.md doesn't exists" which seems that the wildcard is interpreted as a file name. Am I doing something wrong or is it related to this reported bug?
Using npx embedme wiki/script1.md wiki/script.2md wiki/script3.md is working very well.

I'm using Windows and I built the project with node 11.13

@christiannaths
Copy link
Author

christiannaths commented Jul 22, 2019

@caesarcc What happens when you do ls wiki/*.md? Same error? Or does it list the files? Also, what shell are you using? (try $(echo $SHELL) --version, or which sh)

Wups, my bad. Just read the part about how you're on Windows. I'm afraid I can't help, I have no idea how globbing works on Windows.

@zakhenry
Copy link
Owner

🎉 This issue has been resolved in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants