Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Support inline source maps #82

Merged
merged 11 commits into from
Feb 20, 2015
Merged

Support inline source maps #82

merged 11 commits into from
Feb 20, 2015

Conversation

crisptrutski
Copy link
Contributor

Closes #74

var sourceMapFile = path.basename(opts.outFile) + '.map';
output.source += '\n//# sourceMappingURL=' + sourceMapFile;
}

return asp(mkdirp)(path.dirname(path.resolve(basePath, opts.outFile)))
.then(function() {
if (!opts.sourceMaps) return;
if (!output.SourceMap) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

@crisptrutski
Copy link
Contributor Author

Having some race conditions with Cannot call method '_nodeRequire' of undefined when running tests now (via JSX plugin). Settles if running with --watch.

Would love to squish this - something I can block on to know that systemjs is ready?

@guybedford
Copy link
Member

That would be if global.System is undefined. This is still needed unfortunately.

@crisptrutski
Copy link
Contributor Author

Travis fails are just that issue, going see about putting in a diabolical spin loop.

@guybedford
Copy link
Member

I may have fixed this build issue in 75e8eec.



})();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRyZWUvYW1kLTIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7T0FPTyxFQUFFLEdBQUUsQ0FBRyxJQUFFLENBQUU7RUFBRTtBQUFBIn0=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about all these exact source tests - everytime we update compiler implementations we will be needing to update and generate these tests. How do we update the generated code? etc etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it's brittle as hell. Big advantage when test coverage is low is that you don't miss details. Updating the generated code could be as easy as setting an environment variable before running the tests again.

Had pretty good experience with "test everything, even the incidental things" as the initial strategy. You can immediately refactor quickly, and it's hard to write targeted tests without refactoring or abusing mocks and spies (which is often more expensive than no tests..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could replace this full-text match with a few assertions and keep high confidence:

  1. Only one //# sourceMappingURL comment, and it's on the last line
  2. Type is data:application/json;base64
  3. Decoding and parsing it generates a valid source map

@crisptrutski
Copy link
Contributor Author

@guybedford merge?

@@ -22,7 +22,8 @@
"es6-module-loader": "0.14.0",
"mocha": "~2.0.0",
"chai": "^1.10.0",
"react-tools": "^0.12.1"
"react-tools": "^0.12.1",
"atob": "^1.1.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we want to get on the wrong side of the Modularity Wars?!

Thanks, will drop atob.

@crisptrutski
Copy link
Contributor Author

Hit all the feedback I think

var opts = {};
keys.forEach(function(key) {
opts[key] = opts_ && opts_[key];
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this is to allow type inference through the setting of default values.

A common pattern I find useful is:

function prepend(a, b) {
  for (var p in b) {
    if (!(p in a))
      a[p] = b[p];
  }
  return a;
}

function processOpts(opts_, outFile) {
  // apply defaults
  prepend(opts_, {
    config: {},
    lowResSourceMaps: true,
    minify: true,
    normalize: false,
    outFile: outFile || '',
    runtime: false,
    sourceMaps: true,
    sourceMapContents: _opts.sourceMaps == 'inline'
  });
}

Sorry to be a pain...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost added it as extend(defaults, normalize(opts), overrides), but then stopped because really config should also be normalized, and that triggered my subscription to the religion that configuration should never be nested, so then I went back to "smallest thing that meets this nitpickers explicit points" 👹

Sure we could add this prepend form as a "stopgap" ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current behaviour has every default or falsey. Assume your example was just to demonstrate, and you're not wanting to enforce new defaults?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah of course - yes defaults can stay falsey.

@guybedford
Copy link
Member

Looks great, thanks.

@crisptrutski
Copy link
Contributor Author

OK, gave you something similar to your prepend case, but without mutating the input argument. Think it's as good enough as we can get without defining a bunch of helpers to give JS basic data wrangling powers 🔋

(what the hell.. no lambda or wizard emoji when I needed them there)

@guybedford
Copy link
Member

Nice, thanks! In terms of giving JS basic data wrangling powers, Rick Waldron kindly proposed this for us in ES6 :) The pattern going forward for this in JS will be Object.assign (http://www.2ality.com/2014/12/es6-oop.html).

@guybedford
Copy link
Member

Can we rebase? Then good to merge!

* Also ensure content option gets to where it needs to go
* Fix typos around (opts|output).sourceMap(s)
* Fix typos around opts.lowRes(olution)SourceMaps
* Fix typos around inlineSourceMap(s)
* Make exports.inlineSourceMap more visible
* Explicitly list all `opts` keys in one place
* Remove atob dependency
@crisptrutski
Copy link
Contributor Author

Rebased!

Don't link me to articles about OO, I was having such a nice day ☁️

guybedford added a commit that referenced this pull request Feb 20, 2015
@guybedford guybedford merged commit ed2790c into master Feb 20, 2015
@crisptrutski crisptrutski deleted the inline-source-maps branch February 20, 2015 15:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline source maps option
2 participants