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

Ability to skip first directories #15

Open
zba opened this issue Jun 12, 2015 · 2 comments
Open

Ability to skip first directories #15

zba opened this issue Jun 12, 2015 · 2 comments

Comments

@zba
Copy link

zba commented Jun 12, 2015

I have the following compile flow:

babel->browserify->exorciise->sorcery

so I would to apply magic to browserify sourcemaps , but since browserify has no cwd option, it will generate paths relative to project root, so, if generated .js file not in project root path sorcery will not find original map... one possible workaround is symlink, but it would be better to have option like in 'patch' --strip=num (-pnum)

example project tree:

| App
|_Build
   |   |_babeljs
   |      |_some.js
   |      |_sone.js.map
   |_index.js // made from some.js
   |_index.js.map

~/dev/projec/$ sorcery -i index.js
Error: ENOENT, open /usr/dev/project/Build/Build/babeljs/some.js.map
@Rich-Harris
Copy link
Owner

Eek. I've faced a similar problem in the past - in the gobble plugin that wraps browserify, I had to explicitly make the paths absolute otherwise I'd end up in the same situation.

It seems that this is something that should probably be fixed within browserify. It doesn't have a concept of a 'destination' for the file, since it just creates a stream, but perhaps it should have a sourceMapFile option that it uses as a base to generate the relative paths from. I've raised an issue with browserify: browserify/browserify#1303

Incidentally you shouldn't need to use exorcist if you're using sorcery - sorcery will read the inline data URI just as happily as the separate .map file exorcist generates.

@Rich-Harris
Copy link
Owner

@zba FYI there was some discussion the browserify issue tracker, and a second issue has been raised - browserify/browserify#1304. Unfortunately I'm not sure that this is best solved within sorcery in the meantime, since it only addresses the first sourcemaps encountered - any transpilation step could have similar problems, and I don't think there's a particularly good way to address them via configuration options.

I think the best interim solution would be to modify the sourcemap between browserify and sorcery. mold-source-map might be useful here - I haven't used it, but I think it's suitable for this sort of task. Alternatively...

var json = fs.readFileSync('bundle.js.map', 'utf-8');
var map = JSON.parse(json);
map.sourceRoot = '../';
json = JSON.stringify(map);
fs.writeFileSync('bundle.js.map', json);

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