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

main.paths creation order #50

Open
jaumard opened this issue May 7, 2016 · 3 comments
Open

main.paths creation order #50

jaumard opened this issue May 7, 2016 · 3 comments

Comments

@jaumard
Copy link
Contributor

jaumard commented May 7, 2016

When the temp folder is not given by the user, it was added by this repo. But it was create after config.main.paths values. https://github.com/trailsjs/trailpack-core/blob/master/index.js#L47

That's mean if I have :

paths: {
    root: process.cwd(),
    www: path.resolve(process.cwd(), '.tmp', 'public')
  }

This will crash because core try to first create www path and then temp path so a Error: ENOENT: no such file or directory, mkdir '/.tmp/public'

But if now I change and set this :

paths: {
    root: process.cwd(),
    temp: path.resolve(process.cwd(), '.tmp'),
    www: path.resolve(process.cwd(), '.tmp', 'public')
  }

All is working because temp is create before www.

My opinion is if temp, socket and log are added by core so they have to be create first.

@catrielmuller
Copy link
Member

@jaumard another solution is implement this https://github.com/substack/node-mkdirp and make a mkdirp.sync it the same but create a parents directories if dont exist.

@jaumard
Copy link
Contributor Author

jaumard commented Sep 15, 2016

@catrielmuller it will be a better solution ^^ but the main team want to keep trails deps to the minimum. That's why I didn't put this solution. Thoughts @trailsjs/maintainers ?

@catrielmuller
Copy link
Member

@jaumard if clone the function inside of the project?
its a fifty lines of code.

mkdirP.sync = function sync (p, opts, made) {
    if (!opts || typeof opts !== 'object') {
        opts = { mode: opts };
    }

    var mode = opts.mode;
    var xfs = opts.fs || fs;

    if (mode === undefined) {
        mode = _0777 & (~process.umask());
    }
    if (!made) made = null;

    p = path.resolve(p);

    try {
        xfs.mkdirSync(p, mode);
        made = made || p;
    }
    catch (err0) {
        switch (err0.code) {
            case 'ENOENT' :
                made = sync(path.dirname(p), opts, made);
                sync(p, opts, made);
                break;

            // In the case of any other error, just see if there's a dir
            // there already.  If so, then hooray!  If not, then something
            // is borked.
            default:
                var stat;
                try {
                    stat = xfs.statSync(p);
                }
                catch (err1) {
                    throw err0;
                }
                if (!stat.isDirectory()) throw err0;
                break;
        }
    }

    return made;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants