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 issues with styles in addon directory #56 #57

Closed
wants to merge 9 commits into from

Conversation

dukex
Copy link
Collaborator

@dukex dukex commented Jun 10, 2015

I don't know if this approach is the better way to fix the issues, maybe I need understand more about broccoli and ember-cli internals functions, but It's fix the problems(in ember-cli-sass) mentioned on ember-cli/ember-cli#4084 and fix issue #56

For understand why I made this checks please see @stefanpenner anwser on ember-cli/ember-cli#4258

@stefanpenner
Copy link
Collaborator

i'll try to make time later this week to review this.

function isAddonTree(inputPath) {
return inputPath === "/";
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This function should be at the bottom of the file.

@simonexmachina
Copy link
Collaborator

I'm okay with this solution, but only if it relies on stable behaviour from ember-cli. What do you think @stefanpenner?

@dukex
Copy link
Collaborator Author

dukex commented Jun 15, 2015

@stefanpenner any feedback?

@stefanpenner
Copy link
Collaborator

@stefanpenner any feedback?

haven't had a chance yet

// When ember-cli preprocess addon style the inputPath is '/',
// add the '/addon/styles' to try found addon sass files
var root = isAddonTree(inputPath) ? tree : ".";
var filePath = path.join(root, inputPath, file);

Choose a reason for hiding this comment

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

@dukex this line is throwing an error when I try to build an application that uses an addon with this branch:

TypeError: Arguments to path.join must be strings
    at Object.posix.join (path.js:488:13)
    at tryFile (node_modules/ember-cli-sass/index.js:43:25)

where root evaluated to { read: [Function], cleanup: [Function] }

Choose a reason for hiding this comment

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

I have submitted a PR dukex#1 to fix the mentioned issue.

justin-lau and others added 2 commits June 21, 2015 03:26
```
TypeError: Arguments to path.join must be strings
    at Object.posix.join (path.js:488:13)
    at tryFile (/path/to/app-name/node_modules/addon-name/node_modules/ember-cli-sass/index.js:43:25)
    at /path/to/app-name/node_modules/addon-name/node_modules/ember-cli-sass/index.js:26:15
```

The root of the error is that `ember-cli` passes different `tree` as the
parameter to `toTree()`.

When building an addon that directly uses `ember-cli-sass`, `tree` is a `String`
that contains `"/path/to/your/addon-name/addon/styles"`.

When building an hosting app that indirectly uses `ember-cli-sass` through an
addon, `tree` is an object with a `read()` function that returns
`"/path/to/your/addon-name/addon/styles"`.
Fixed error when building an hosting app that indirectly uses ember-cli-sass through an addon.
@dukex
Copy link
Collaborator Author

dukex commented Jul 1, 2015

Thanks @justin-lau!

@ahouchens
Copy link

Verified that this pull request works perfectly with ember-cli for preprocessing SASS. :) Thanks so much.

@begedin
Copy link

begedin commented Jul 10, 2015

Is there anything the consuming app needs to be doing in order for this PR to work?

It works from the dummy app provided by a developing addon, but vendor.css is empty if I consume the developing addon through an external app.

To elaborate:

  • Addon some-random-addon is using ember-cli-sass (this branch)
    • Only .scss file I have in the addon is addon/styles/addon.scss
  • App my-app is using some-random-addon.
  • sass works in dummy app provided by some-random-addon - vendor.css has content
  • sass doesn't work in my-app - vendor.css is empty.

Am I missing some part of the solution?

  • Does my-app need to depend on ember-cli-sass as well?
  • Does my-app need an empty app[.css|.scss]?
  • Does some-random-addon need an empty app/styles/app[.css|.scss]?

@justin-lau
Copy link

Below is what works for me:

  1. some-random-addon should place ember-cli-sass under dependencies instead of devDependencies.
  2. If you need Sass in my-app, it should also use this same branch of emebr-cli-sass, but it is okay to place it under devDependencies.

@begedin
Copy link

begedin commented Jul 10, 2015

I'm sorry. It was a common mistake on my part. I used npm link to test out the addon and forgot to add it to the list of app's dependencies.

Just in case someone repeats my mistake, the full list of steps to get it working:

  • initialize a new addon
ember addon some-addon
  • add this branch as a dependency (not devDependency):
cd some-addon
npm install --save git+https://github.com/dukex/ember-cli-sass.git#bugfix/addon-styles
  • modify the addon's index.js
// index.js for 'some-addon'
module.exports = {
  name: 'some-addon',
  included: function(app) {
    this._super.included(app);
  }
}
  • create addon.scss
mkdir some-addon/addon/styles
touch some-addon/addon/styles/addon.scss
  • add whatever it is you want to addon.scss.
  • create a new app
cd path/to/parent
ember new my-app
  • use npm link to link the addon with the app
cd path/to/some-addon
npm link
cd path/to/my-app
npm link some-addon
  • add the addon as a dev dependency for the app, manually, by editing package.json of the app
"devDependencies": {
  ...
  "some-addon": "*"
}
  • run the app, it should work now

@ahouchens
Copy link

Perfect walkthrough @begedin.

@Fed03
Copy link

Fed03 commented Jul 14, 2015

+1

@dukex dukex changed the title Fix issues with styles in addon directory #56 [WIP] Fix issues with styles in addon directory #56 Jul 21, 2015
@dukex
Copy link
Collaborator Author

dukex commented Jul 21, 2015

@justin-lau found I bug in windows, I'll check @justin-lau's pull request and remove the '[WIP]' prefix

@dukex
Copy link
Collaborator Author

dukex commented Jul 28, 2015

@vitch do you got same error without extension options?

@vitch
Copy link

vitch commented Jul 29, 2015

Without the extension option when compiling the addons dummy app with this branch I get:

Arguments to path.resolve must be strings
TypeError: Arguments to path.resolve must be strings
    at Object.posix.resolve (path.js:439:13)
    at Object.posix.relative (path.js:505:16)
    at tryFile (/path/to/project/node_modules/ember-cli-sass/index.js:57:17)
    at /path/to/project/node_modules/ember-cli-sass/index.js:26:15
    at Array.reduce (native)
    at SASSPlugin.toTree (/path/to/project/node_modules/ember-cli-sass/index.js:20:48)
    at /path/to/project/node_modules/ember-component-css/node_modules/ember-cli-preprocess-registry/preprocessors.js:186:26
    at Array.forEach (native)
    at processPlugins (/path/to/project/node_modules/ember-component-css/node_modules/ember-cli-preprocess-registry/preprocessors.js:184:11)
    at module.exports.preprocessCss (/path/to/project/node_modules/ember-component-css/node_modules/ember-cli-preprocess-registry/preprocessors.js:154:10)

@dukex
Copy link
Collaborator Author

dukex commented Jul 29, 2015

@vitch I will investigate it
/cc @justin-lau

@sandstrom
Copy link

@dukex If this issue is resolved, will that also solve ember-cli/ember-cli#2905?

@dukex
Copy link
Collaborator Author

dukex commented Aug 11, 2015

@vitch I fix it! Update the repository and check again

Sorry delay

@dukex
Copy link
Collaborator Author

dukex commented Aug 11, 2015

@sandstrom I believe not, the ember-cli/ember-cli#2905 example app don't uses ember-cli-sass and this pull request don't has effect in that example

@dukex dukex changed the title [WIP] Fix issues with styles in addon directory #56 Fix issues with styles in addon directory #56 Aug 11, 2015
@simonexmachina
Copy link
Collaborator

I've gotta say that I think this is really an issue with ember-cli, and it looks that ember-cli/ember-cli#3344 fixes the problem in ember-cli. This PR seems to introduce quite a bit of coupling to ember-cli internals, so I'd prefer to wait until the underlying issue is resolved in ember-cli.

In the meantime addon authors can simply specify the extension option as a workaround.

@ahouchens
Copy link

@aexmachina "In the meantime addon authors can simply specify the extension option as a workaround."

That's not accurate. That is another issue which this pull request doesn't address. The only way my files get preprocessed is if I specify the extension option AND point to this PR in my package.json.

@simonexmachina
Copy link
Collaborator

Aha, okay thanks for the info. I will reopen and review tomorrow.

On Tue, 11 Aug 2015 23:48 Alex Houchens notifications@github.com wrote:

@aexmachina https://github.com/aexmachina "In the meantime addon
authors can simply specify the extension option as a workaround."

That's not accurate. That is another issue which this pull request doesn't
address. The only way my files get preprocessed is if I specify the
extension option AND point to this PR in my package.json.


Reply to this email directly or view it on GitHub
#57 (comment)
.

@ahouchens
Copy link

Great thanks @aexmachina!

@@ -33,8 +33,36 @@ SASSPlugin.prototype.toTree = function(tree, inputPath, outputPath, inputOptions
}, []);

function tryFile(file) {
var filePath = path.join('.', inputPath, file);
return fs.existsSync(filePath) ? filePath : false;
/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Double-asterisk ** denotes JSDoc, so this should be a single asterisk.

@simonexmachina
Copy link
Collaborator

@stefanpenner any feedback on this? It seems quite tied to implementation details in ember-cli, but I'm happy to go with your advice on this.

@dukex
Copy link
Collaborator Author

dukex commented Aug 12, 2015

I believe the ember-cli/ember-cli#3344 will help us to remove this hack

@simonexmachina
Copy link
Collaborator

I've asked @rwjblue for an opinion on whether we should add this hack or wait for the underlying issues to be fixed in ember-cli.

@dukex
Copy link
Collaborator Author

dukex commented Aug 21, 2015

I tried to run ember-cli/ember-cli#3344 but many tests are failed

@alexmngn
Copy link

Hi there, when will this pull request supposed be merged into master?

@simonexmachina
Copy link
Collaborator

We're trying to avoid merging this, because it's basically a hack to get around a problem in ember-cli which should be fixed when ember-cli/ember-cli#3344 is merged. @stefanpenner should we just merge this and then pull it out when the problem in ember-cli is resolved?

@stefanpenner
Copy link
Collaborator

cc @rwjblue whats the status if your fix?

@dukex dukex mentioned this pull request Oct 1, 2015
@dukex
Copy link
Collaborator Author

dukex commented Oct 1, 2015

Hi everyone, I made pull request #78 to fix the issue addressed in this pull request, but without hack and using other approach, now I using the #78 in my projects and works fine.

@dukex
Copy link
Collaborator Author

dukex commented Oct 8, 2015

Closing in favor of #78

@dukex dukex closed this Oct 8, 2015
@dukex dukex deleted the bugfix/addon-styles branch February 14, 2017 13:20
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

Successfully merging this pull request may close these issues.

10 participants