Skip to content

Commit cf072ee

Browse files
authored
Merge pull request #220 from timlindvall/fix-module-name
2 parents c78a6ec + 36f19bb commit cf072ee

File tree

158 files changed

+33420
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+33420
-4
lines changed

packages/ember-css-modules/lib/modules-preprocessor.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ module.exports = class ModulesPreprocessor {
1515
this._modulesTree = null;
1616
this._modulesBasePath = null;
1717
this._modulesBridge = new Bridge();
18+
19+
/*
20+
* The addon name we should use to look up modules.
21+
* Uses moduleName if defined, else uses the parent/package name.
22+
*/
23+
this._ownerName = null;
24+
25+
/*
26+
* The parent/package name. This is used as a fallback to look up
27+
* paths that may reference the package name instead of the
28+
* module name. (See resolve-path.js)
29+
*/
30+
this._parentName = null;
1831
}
1932

2033
toTree(inputTree, path) {
@@ -37,10 +50,17 @@ module.exports = class ModulesPreprocessor {
3750
});
3851
}
3952

53+
// If moduleName is defined, that should override the parent's name.
54+
// Otherwise, the template and generated module will disagree as to what the path should be.
55+
let ownerParent = this.owner.getParent();
56+
this._parentName = this.owner.getParentName();
57+
let ownerName = ownerParent.moduleName ? ownerParent.moduleName() : this._parentName;
58+
this._ownerName = ownerName;
59+
4060
let modulesSources = new ModuleSourceFunnel(inputRoot, modulesInput, {
4161
include: ['**/*.' + this.owner.getFileExtension()],
4262
outputRoot,
43-
parentName: this.owner.getParentName()
63+
parentName: ownerName,
4464
});
4565

4666
let modulesTree = new (require('broccoli-css-modules'))(modulesSources, {
@@ -184,10 +204,12 @@ module.exports = class ModulesPreprocessor {
184204

185205
return this._resolvePath(importPath, fromFile, {
186206
defaultExtension: this.owner.getFileExtension(),
187-
ownerName: this.owner.getParentName(),
207+
ownerName: this._ownerName,
208+
parentName: this._parentName,
188209
addonModulesRoot: this.owner.getAddonModulesRoot(),
189210
root: ensurePosixPath(this._modulesTree.inputPaths[0]),
190-
parent: this.owner.getParent()
211+
parent: this.owner.getParent(),
212+
ui: this.owner.ui
191213
});
192214
}
193215
};

packages/ember-css-modules/lib/resolve-path.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ module.exports = function resolvePath(importPath, fromFile, options) {
1010
return resolveRelativePath(pathWithExtension, fromFile, options);
1111
} else if (isLocalPath(pathWithExtension, options)) {
1212
return resolveLocalPath(pathWithExtension, fromFile, options);
13+
} else if (isLocalPathWithOldPackageNameRef(pathWithExtension, options)) {
14+
const amendedPathWithExtension = pathWithExtension.replace(options.parentName, options.ownerName);
15+
options.ui.writeWarnLine(
16+
'For addons that define a moduleName, you should reference any CSS Modules provided by that addon ' +
17+
'using its moduleName instead of the package name.\n' +
18+
'Current path: ' + importPath + '\n' +
19+
'Replace with: ' + importPath.replace(options.parentName, options.ownerName) + '\n' +
20+
'File: ' + fromFile
21+
);
22+
return resolveLocalPath(amendedPathWithExtension, fromFile, options);
1323
} else {
1424
return resolveExternalPath(pathWithExtension, importPath, fromFile, options);
1525
}
@@ -23,6 +33,10 @@ function isLocalPath(importPath, options) {
2333
return importPath.indexOf(options.ownerName + '/') === 0;
2434
}
2535

36+
function isLocalPathWithOldPackageNameRef(importPath, options) {
37+
return (options.ownerName !== options.parentName) && importPath.indexOf(options.parentName + '/') === 0;
38+
}
39+
2640
function resolveRelativePath(importPath, fromFile, options) {
2741
let absolutePath = ensurePosixPath(path.resolve(path.dirname(fromFile), importPath));
2842
return internalDep(absolutePath, options);
@@ -49,7 +63,12 @@ function resolveLocalPath(importPath, fromFile, options) {
4963
function resolveExternalPath(importPath, originalPath, fromFile, options) {
5064
let baseIndex = importPath[0] === '@' ? importPath.indexOf('/') + 1 : 0;
5165
let addonName = importPath.substring(0, importPath.indexOf('/', baseIndex));
52-
let addon = options.parent.addons.find(addon => addon.name === addonName);
66+
let addon = options.parent.addons.find((addon) => {
67+
if (addon.moduleName) {
68+
return addon.moduleName() === addonName;
69+
}
70+
return addon.name === addonName;
71+
});
5372

5473
if (!addon) {
5574
throw new Error(
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
8+
[*]
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
indent_style = space
14+
indent_size = 2
15+
16+
[*.hbs]
17+
insert_final_newline = false
18+
19+
[*.{diff,md}]
20+
trim_trailing_whitespace = false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
/**
3+
Ember CLI sends analytics information by default. The data is completely
4+
anonymous, but there are times when you might want to disable this behavior.
5+
6+
Setting `disableAnalytics` to true will prevent any data from being sent.
7+
*/
8+
"disableAnalytics": false
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# unconventional js
2+
/blueprints/*/files/
3+
/vendor/
4+
5+
# compiled output
6+
/dist/
7+
/tmp/
8+
9+
# dependencies
10+
/bower_components/
11+
/node_modules/
12+
13+
# misc
14+
/coverage/
15+
!.*
16+
17+
# ember-try
18+
/.node_modules.ember-try/
19+
/bower.json.ember-try
20+
/package.json.ember-try
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module.exports = {
2+
root: true,
3+
parser: 'babel-eslint',
4+
parserOptions: {
5+
ecmaVersion: 2018,
6+
sourceType: 'module'
7+
},
8+
plugins: [
9+
'ember'
10+
],
11+
extends: [
12+
'eslint:recommended',
13+
'plugin:ember/recommended'
14+
],
15+
env: {
16+
browser: true
17+
},
18+
rules: {
19+
'ember/no-jquery': 'error'
20+
},
21+
overrides: [
22+
// node files
23+
{
24+
files: [
25+
'.eslintrc.js',
26+
'.template-lintrc.js',
27+
'ember-cli-build.js',
28+
'index.js',
29+
'testem.js',
30+
'blueprints/*/index.js',
31+
'config/**/*.js',
32+
'tests/dummy/config/**/*.js'
33+
],
34+
excludedFiles: [
35+
'addon/**',
36+
'addon-test-support/**',
37+
'app/**',
38+
'tests/dummy/app/**'
39+
],
40+
parserOptions: {
41+
sourceType: 'script'
42+
},
43+
env: {
44+
browser: false,
45+
node: true
46+
},
47+
plugins: ['node'],
48+
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
49+
// add your custom rules and overrides for node files here
50+
})
51+
}
52+
]
53+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist/
5+
/tmp/
6+
7+
# dependencies
8+
/bower_components/
9+
/node_modules/
10+
11+
# misc
12+
/.env*
13+
/.pnp*
14+
/.sass-cache
15+
/connect.lock
16+
/coverage/
17+
/libpeerconnection.log
18+
/npm-debug.log*
19+
/testem.log
20+
/yarn-error.log
21+
22+
# ember-try
23+
/.node_modules.ember-try/
24+
/bower.json.ember-try
25+
/package.json.ember-try
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# compiled output
2+
/dist/
3+
/tmp/
4+
5+
# dependencies
6+
/bower_components/
7+
8+
# misc
9+
/.bowerrc
10+
/.editorconfig
11+
/.ember-cli
12+
/.env*
13+
/.eslintignore
14+
/.eslintrc.js
15+
/.git/
16+
/.gitignore
17+
/.template-lintrc.js
18+
/.travis.yml
19+
/.watchmanconfig
20+
/bower.json
21+
/config/ember-try.js
22+
/CONTRIBUTING.md
23+
/ember-cli-build.js
24+
/testem.js
25+
/tests/
26+
/yarn.lock
27+
.gitkeep
28+
29+
# ember-try
30+
/.node_modules.ember-try/
31+
/bower.json.ember-try
32+
/package.json.ember-try
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
extends: 'recommended'
5+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
language: node_js
3+
node_js:
4+
# we recommend testing addons with the same minimum supported node version as Ember CLI
5+
# so that your addon works for all apps
6+
- "8"
7+
8+
sudo: false
9+
dist: trusty
10+
11+
addons:
12+
chrome: stable
13+
14+
cache:
15+
yarn: true
16+
17+
env:
18+
global:
19+
# See https://git.io/vdao3 for details.
20+
- JOBS=1
21+
22+
branches:
23+
only:
24+
- master
25+
# npm version tags
26+
- /^v\d+\.\d+\.\d+/
27+
28+
jobs:
29+
fail_fast: true
30+
allow_failures:
31+
- env: EMBER_TRY_SCENARIO=ember-canary
32+
33+
include:
34+
# runs linting and tests with current locked deps
35+
36+
- stage: "Tests"
37+
name: "Tests"
38+
install:
39+
- yarn install --non-interactive
40+
script:
41+
- yarn lint:hbs
42+
- yarn lint:js
43+
- yarn test
44+
45+
- name: "Floating Dependencies"
46+
script:
47+
- yarn test
48+
49+
# we recommend new addons test the current and previous LTS
50+
# as well as latest stable release (bonus points to beta/canary)
51+
- stage: "Additional Tests"
52+
env: EMBER_TRY_SCENARIO=ember-lts-3.4
53+
- env: EMBER_TRY_SCENARIO=ember-lts-3.8
54+
- env: EMBER_TRY_SCENARIO=ember-release
55+
- env: EMBER_TRY_SCENARIO=ember-beta
56+
- env: EMBER_TRY_SCENARIO=ember-canary
57+
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
58+
59+
before_install:
60+
- curl -o- -L https://yarnpkg.com/install.sh | bash
61+
- export PATH=$HOME/.yarn/bin:$PATH
62+
63+
install:
64+
- yarn install --no-lockfile --non-interactive
65+
66+
script:
67+
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO

0 commit comments

Comments
 (0)