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

Fix all the things #100

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
78e9b9d
[REFACTOR] stubs now gets imports provided via set, rather than extra…
stefanpenner Sep 13, 2016
eae97f3
first pass of import/export identifier mangling
stefanpenner Sep 13, 2016
c388ac6
more ember-cli 1.x related removals
stefanpenner Sep 13, 2016
b4e6a04
allow StubGenerator -> CachingBrowserify to overwrite output from app.
stefanpenner Sep 13, 2016
b0387a9
remove more ember-cli 1.x stuff
stefanpenner Sep 13, 2016
d29a10e
StubGenerator output needs to be merged into tree
stefanpenner Sep 13, 2016
1532cac
resolve actual versions
stefanpenner Sep 14, 2016
9a81644
refactor tests (split up concerns)
stefanpenner Sep 14, 2016
71ab74f
Fixed test for multiple input rewrites.
nathanhammond Sep 14, 2016
cdf0067
add jshinting to tests
stefanpenner Sep 14, 2016
831f464
fix hinting
stefanpenner Sep 14, 2016
ee94775
fixup spacing
stefanpenner Sep 14, 2016
d30025b
use chai-files
stefanpenner Sep 14, 2016
b3f7faa
tidy up test files
stefanpenner Sep 14, 2016
75f48c1
more cleanup
stefanpenner Sep 14, 2016
6548bfa
Add in Ember Addon boilerplate.
nathanhammond Sep 14, 2016
0683633
Fix CI.
nathanhammond Sep 14, 2016
f02b3a5
Add in VS Code debug profile for mocha.
nathanhammond Sep 14, 2016
8fa1b0d
Use string positions to handle replacement.
nathanhammond Sep 15, 2016
2ef155c
Extract rewrite-imports.
nathanhammond Sep 15, 2016
74ab985
Alphabetize package.json
nathanhammond Sep 15, 2016
b65c162
npm fixtures
nathanhammond Sep 15, 2016
a7f4b5d
Set up top-level addon fixtures.
nathanhammond Sep 15, 2016
0850b99
Make sure caching-browserify (a legacy plugin) toStrings helpfully, s…
stefanpenner Sep 16, 2016
d25ff36
add a very simple/basic scenario (that works)
stefanpenner Sep 16, 2016
a60d9f9
remove unused file
stefanpenner Sep 16, 2016
e5f3e89
lazily require browserify, only injuring its load cost when used.
stefanpenner Sep 16, 2016
1f44127
only include the part of lodash we use.
stefanpenner Sep 16, 2016
47055a5
update dependency to be more accurate
stefanpenner Sep 16, 2016
8f250bb
fix lodash usage
stefanpenner Sep 16, 2016
555d137
update example to more closely match what works
stefanpenner Sep 16, 2016
f605a3b
cross platform setup script
stefanpenner Sep 16, 2016
062f674
remove trailing whitespace
stefanpenner Sep 16, 2016
e3c8b59
update example to work with in-repo addons
stefanpenner Sep 16, 2016
2c686a0
update symlink/junction hack to work in more cases
stefanpenner Sep 16, 2016
f3e0231
Rework tests, add reexports scenario.
nathanhammond Sep 16, 2016
59004b2
Properly set on prepublish.
nathanhammond Sep 16, 2016
69cc443
Revert "add a very simple/basic scenario (that works)"
nathanhammond Sep 18, 2016
772c859
Structure for doing the right thing in the vendor hook.
nathanhammond Sep 18, 2016
80b0caf
Merge pull request #106 from nathanhammond/fix-all-the-things
stefanpenner Sep 18, 2016
0ef7aa4
Partial rewrite of preprocessor approach.
nathanhammond Sep 19, 2016
b6f11dc
Move away from postprocessTree.
nathanhammond Sep 19, 2016
80597f7
Properly set basedir per target.
nathanhammond Sep 19, 2016
0f5a959
Merge pull request #109 from nathanhammond/fix-all-the-things
nathanhammond Sep 19, 2016
03c9c95
add comments, making it easier to understand where stuff is actually …
stefanpenner Sep 20, 2016
f5908b9
only rewrite if rewriting is required
stefanpenner Sep 20, 2016
a70c006
remove optimization for now. Bring back with tests.
stefanpenner Sep 20, 2016
e314119
Use the proper hook for setting up the registry.
nathanhammond Sep 22, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@
/libpeerconnection.log
npm-debug.log
testem.log

# linking ember-browserify here, so addon-discovery bug is worked-around.
# linking the dir, so as:
# * not to create a cycyle
# * use the correct version of ember-browserify
# * use symlinks when possible, but correctly fallback to junctions on windows
# (if no symlinks are used)
# * symlinked files turn out to be realpathSync'd before being loaded into
# node, which means this should nicely trick node. Atleast in posix, although
# in windows this may also be true with junctions... Ultimately this is just
# for testing, and its working around a potential addon-discovery bug which
# will hopefully soon be addressed.
tests/dummy/lib/modern/node_modules/ember-browserify/lib
tests/dummy/lib/outdated/node_modules/ember-browserify/lib
41 changes: 35 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
---
language: node_js
sudo: false
before_install:
- npm install -g npm@2
- npm install -g npm
node_js:
- "0.12"
- node

cache:
directories:
- node_modules

env:
# we recommend testing LTS's and latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-1.13
- EMBER_TRY_SCENARIO=ember-lts-2.4
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary

matrix:
include:
- node_js: '0.12'
- node_js: node
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- npm config set spin false
- npm install -g bower
- bower --version
- npm install phantomjs-prebuilt
- node_modules/phantomjs-prebuilt/bin/phantomjs --version

install:
- npm install
- bower install

script:
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Mocha",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["node-tests"],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
}
]
}
Empty file added addon/.gitkeep
Empty file.
Empty file added app/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:
test_script:
# Output useful info for debugging.
- npm version
- cmd: npm test
- cmd: npm run node-test

# Don't actually build.
build: off
Expand Down
17 changes: 17 additions & 0 deletions bin/install-ember-addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

var symlinkOrCopy = require('symlink-or-copy');
var path = require('path');
var rimraf = require('rimraf');
var fs = require('fs');

['modern', 'outdated'].forEach(function(inRepoAddon) {
var source = path.resolve(__dirname, '..', 'lib/');
var target = path.resolve(__dirname, '..', 'tests/dummy/lib', inRepoAddon, 'node_modules/ember-browserify/lib/');

console.log('rimraf', target);
rimraf.sync(target);

console.log('symlink', source, target)
symlinkOrCopy.sync(source, target);
});
7 changes: 7 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "ember-browserify",
"dependencies": {
"ember": "~2.8.0",
"ember-cli-shims": "0.1.1"
}
}
60 changes: 60 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*jshint node:true*/
module.exports = {
scenarios: [
{
name: 'ember-1.13',
bower: {
dependencies: {
'ember': '~1.13.0'
},
resolutions: {
'ember': '~1.13.0'
}
}
},
{
name: 'ember-lts-2.4',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-4'
},
resolutions: {
'ember': 'lts-2-4'
}
}
},
{
name: 'ember-release',
bower: {
dependencies: {
'ember': 'components/ember#release'
},
resolutions: {
'ember': 'release'
}
}
},
{
name: 'ember-beta',
bower: {
dependencies: {
'ember': 'components/ember#beta'
},
resolutions: {
'ember': 'beta'
}
}
},
{
name: 'ember-canary',
bower: {
dependencies: {
'ember': 'components/ember#canary'
},
resolutions: {
'ember': 'canary'
}
}
}
]
};
6 changes: 6 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*jshint node:true*/
'use strict';

module.exports = function(/* environment, appConfig */) {
return { };
};
18 changes: 18 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*jshint node:true*/
/* global require, module */
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
var app = new EmberAddon(defaults, {
// Add options here
});

/*
This build file specifies the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
};
1 change: 0 additions & 1 deletion index.js

This file was deleted.

4 changes: 4 additions & 0 deletions lib/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"node": true,
"browser": false
}
61 changes: 38 additions & 23 deletions lib/caching-browserify.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

var fs = require('fs');
var path = require('path');
var browserify = require('browserify');
var helpers = require('broccoli-kitchen-sink-helpers');
var RSVP = require('rsvp');
var CoreObject = require('core-object');
var mapSeries = require('promise-map-series');
var merge = require('lodash').merge;
var merge = require('lodash.merge');
var rimraf = require('rimraf');
var symlinkOrCopy = require('symlink-or-copy');
var quickTemp = require('quick-temp');
Expand All @@ -16,7 +17,7 @@ var debug = require('debug')('ember-browserify:caching-browserify');
var through = require('through2');

module.exports = CoreObject.extend({
init: function(inputTree, options){
init: function(inputTree, options) {
if (!options) {
options = {};
}
Expand All @@ -28,11 +29,12 @@ module.exports = CoreObject.extend({
this.fullPaths = typeof options.fullPaths !== 'undefined' ? options.fullPaths : true;
this.outputFile = options.outputFile || 'browserify/browserify.js';
this.cache = {};

quickTemp.makeOrRemake(this, '_inputStaging');
quickTemp.makeOrRemake(this, '_destDir');
},

description: 'ember-browserify',
description: 'CachingBrowserify',

cleanup: function() {
if (this._destDir) {
Expand All @@ -46,25 +48,32 @@ module.exports = CoreObject.extend({
}
},

toString: function() {
return '[' + this.description + ']';
},

read: function (readTree) {
var self = this;
return readTree(this.inputTree).then(function(inDir){
return self.checkCache(inDir).then(function(cacheValid){

return readTree(this.inputTree).then(function(inDir) {
return self.checkCache(inDir).then(function(cacheValid) {
if (!self._outputCache || !cacheValid) {
return self._rebuild(inDir);
}
});
}).then(function(){
}).then(function() {
rimraf.sync(self._destDir);
symlinkOrCopy.sync(self._outputCache, self._destDir);
return self.watchNodeModules(readTree).then(function(){

return self.watchNodeModules(readTree).then(function() {
return self._destDir;
});
});
},

_rebuild: function(inDir){
var self = this;

this._watchModules = Object.create(null);

// _inputStaging needs to stay at the same path, because the
Expand All @@ -74,7 +83,8 @@ module.exports = CoreObject.extend({

symlinkOrCopy.sync(inDir + '/' + this.inFile, this._inputStaging + '/' + this.inFile);
quickTemp.makeOrRemake(this, '_outputCache');
return this.updateCache(this._outputCache).catch(function(err){

return this.updateCache(this._outputCache).catch(function(err) {
rimraf.sync(self._outputCache);
delete self._outputCache;
throw err;
Expand All @@ -98,10 +108,10 @@ module.exports = CoreObject.extend({
debug: this.enableSourcemap
}, this.browserifyOptions);

var b = browserify(opts);
var b = require('browserify')(opts);
['transforms', 'externals', 'ignores', 'includes'].forEach(function(thing) {
if (!opts[thing]) { return; }
opts[thing].forEach(function(args){
opts[thing].forEach(function(args) {
if (!Array.isArray(args)) {
args = [args];
}
Expand All @@ -114,9 +124,10 @@ module.exports = CoreObject.extend({
b = b[thing.replace(/s$/, '')].apply(b, args);
});
});

b.add('./' + self.inFile);

b.on('package', function(pkg){
b.on('package', function(pkg) {
// browserify *used to* reliably put the package's directory in
// pkg.__dirname. But as of browser-resolve 1.7.0 that isn't
// true, and we sometimes get a value here like
Expand All @@ -137,7 +148,7 @@ module.exports = CoreObject.extend({
self._watchModules[pkgDir] = true;
});

b.on('dep', function (dep) {
b.on('dep', function(dep) {
dep.source = derequire(dep.source);
if (typeof dep.id === 'string') {
self.cache[dep.id] = dep;
Expand All @@ -158,7 +169,7 @@ module.exports = CoreObject.extend({
// to prevent unwanted interactions with other code when concatenated
// See https://github.com/ef4/ember-browserify/issues/63
// and https://github.com/substack/node-browserify/issues/806
b.pipeline.get('wrap').push(through.obj(function (row, enc, next) {
b.pipeline.get('wrap').push(through.obj(function(row, enc, next) {
var contents = row.toString();
if (contents[contents.length - 1] === ')') {
contents += ';';
Expand All @@ -178,14 +189,18 @@ module.exports = CoreObject.extend({
var self = this;
fs.mkdirSync(path.dirname(outPath));
var start = Date.now();
return new RSVP.Promise(function (resolve, reject) {
self.bundler().bundle(function (err, data) {
debug('bundle in: %dms', Date.now() - start);
if (err) {
reject(err);
} else {
fs.writeFileSync(outPath, data);
resolve(destDir);
return new RSVP.Promise(function(resolve, reject) {
self.bundler().bundle(function(err, data) {
try {
debug('bundle in: %dms', Date.now() - start);
if (err) {
reject(err);
} else {
fs.writeFileSync(outPath, data);
resolve(destDir);
}
} catch(e) {
reject(e);
}
});
});
Expand All @@ -195,7 +210,7 @@ module.exports = CoreObject.extend({
var self = this;
var root = self.normalizePath(self.root);

return mapSeries(Object.keys(self._watchModules), function(dir){
return mapSeries(Object.keys(self._watchModules), function(dir) {
if (!root || root.indexOf(self.normalizePath(dir)) !== 0){
return readTree(dir);
}
Expand Down
Loading