ember-css-modules 1.3.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { computed, defineProperty } from '@ember/object';
4
4
  import Mixin from '@ember/object/mixin';
5
5
  import { dasherize } from '@ember/string';
6
6
  import { getOwner } from '@ember/application';
7
- import { assert } from '@ember/debug';
7
+ import { assert, deprecate } from '@ember/debug';
8
8
 
9
9
  export default Mixin.create({
10
10
  localClassNames: null,
@@ -42,6 +42,22 @@ export default Mixin.create({
42
42
  layout
43
43
  );
44
44
 
45
+ deprecate(
46
+ 'Support for `localClassNames`, `localClassNameBindings` and the `@localClassName` and `@localClassNames` ' +
47
+ 'decorators will be removed in the next major release of ember-css-modules. The `' + name + '` component ' +
48
+ 'uses one or more of these APIs. See the ECM 1.5.0 release notes for further details and migration options: ' +
49
+ 'https://github.com/salsify/ember-css-modules/releases/tag/v1.5.0',
50
+ false,
51
+ {
52
+ id: 'ember-css-modules.classic-component-apis',
53
+ for: 'ember-css-modules',
54
+ until: '2.0.0',
55
+ since: {
56
+ enabled: '1.5.0'
57
+ }
58
+ }
59
+ );
60
+
45
61
  // Since https://github.com/emberjs/ember.js/pull/18096
46
62
  if (typeof layout === 'function') layout = layout(getOwner(this));
47
63
 
package/index.js CHANGED
@@ -43,7 +43,13 @@ module.exports = {
43
43
 
44
44
  treeForAddon() {
45
45
  let addonTree = this._super.treeForAddon.apply(this, arguments);
46
- return new MergeTrees([addonTree, `${__dirname}/vendor`]);
46
+
47
+ // Allow to opt-out from automatic Component.reopen()
48
+ if (this.cssModulesOptions.patchClassicComponent !== false) {
49
+ return new MergeTrees([addonTree, `${__dirname}/vendor`]);
50
+ } else {
51
+ return addonTree;
52
+ }
47
53
  },
48
54
 
49
55
  cacheKeyForTree(treeType) {
@@ -0,0 +1,18 @@
1
+ const semver = require('semver');
2
+ const postcssVersion = require('postcss/package.json').version;
3
+
4
+ if (semver.lt(postcssVersion, '8.0.0')) {
5
+ module.exports = require('postcss').plugin;
6
+ } else {
7
+ module.exports = function(name, callback) {
8
+ let plugin = (options = {}) => {
9
+ let handler = callback(options);
10
+ return {
11
+ postcssPlugin: name,
12
+ Once: handler
13
+ };
14
+ };
15
+ plugin.postcss = true;
16
+ return plugin;
17
+ };
18
+ }
@@ -15,6 +15,19 @@ module.exports = class ModulesPreprocessor {
15
15
  this._modulesTree = null;
16
16
  this._modulesBasePath = null;
17
17
  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;
18
31
  }
19
32
 
20
33
  toTree(inputTree, path) {
@@ -37,10 +50,17 @@ module.exports = class ModulesPreprocessor {
37
50
  });
38
51
  }
39
52
 
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
+
40
60
  let modulesSources = new ModuleSourceFunnel(inputRoot, modulesInput, {
41
61
  include: ['**/*.' + this.owner.getFileExtension()],
42
62
  outputRoot,
43
- parentName: this.owner.getParentName()
63
+ parentName: ownerName,
44
64
  });
45
65
 
46
66
  let modulesTree = new (require('broccoli-css-modules'))(modulesSources, {
@@ -174,7 +194,7 @@ module.exports = class ModulesPreprocessor {
174
194
  }
175
195
 
176
196
  rootPathPlugin() {
177
- return require('postcss').plugin('root-path-tag', () => (css) => {
197
+ return require('./make-postcss-plugin')('root-path-tag', () => (css) => {
178
198
  css.source.input.rootPath = this._modulesTree.inputPaths[0];
179
199
  });
180
200
  }
@@ -184,10 +204,12 @@ module.exports = class ModulesPreprocessor {
184
204
 
185
205
  return this._resolvePath(importPath, fromFile, {
186
206
  defaultExtension: this.owner.getFileExtension(),
187
- ownerName: this.owner.getParentName(),
207
+ ownerName: this._ownerName,
208
+ parentName: this._parentName,
188
209
  addonModulesRoot: this.owner.getAddonModulesRoot(),
189
210
  root: ensurePosixPath(this._modulesTree.inputPaths[0]),
190
- parent: this.owner.getParent()
211
+ parent: this.owner.getParent(),
212
+ ui: this.owner.ui
191
213
  });
192
214
  }
193
215
  };
@@ -31,7 +31,8 @@ module.exports = class OutputStylesPreprocessor {
31
31
  debug('running postprocess plugins: %o', postprocessPlugins);
32
32
 
33
33
  concat = new PostCSS(concat, {
34
- plugins: postprocessPlugins
34
+ plugins: postprocessPlugins,
35
+ exclude: ['**/*.map']
35
36
  });
36
37
  }
37
38
 
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const postcss = require('postcss');
4
3
  const ensurePosixPath = require('ensure-posix-path');
4
+ const makePostCSSPlugin = require('./make-postcss-plugin');
5
5
 
6
6
  // Report all discovered @after-module rules in a module and strip them out of the source
7
- module.exports = postcss.plugin('ember-css-modules-ordering', (options) => {
7
+ module.exports = makePostCSSPlugin('ember-css-modules-ordering', (options) => {
8
8
  return (css) => {
9
9
  let dependencies = [];
10
10
  let input = css.source.input;
@@ -10,6 +10,16 @@ module.exports = function resolvePath(importPath, fromFile, options) {
10
10
  return resolveRelativePath(pathWithExtension, fromFile, options);
11
11
  } else if (isLocalPath(pathWithExtension, options)) {
12
12
  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);
13
23
  } else {
14
24
  return resolveExternalPath(pathWithExtension, importPath, fromFile, options);
15
25
  }
@@ -23,6 +33,10 @@ function isLocalPath(importPath, options) {
23
33
  return importPath.indexOf(options.ownerName + '/') === 0;
24
34
  }
25
35
 
36
+ function isLocalPathWithOldPackageNameRef(importPath, options) {
37
+ return (options.ownerName !== options.parentName) && importPath.indexOf(options.parentName + '/') === 0;
38
+ }
39
+
26
40
  function resolveRelativePath(importPath, fromFile, options) {
27
41
  let absolutePath = ensurePosixPath(path.resolve(path.dirname(fromFile), importPath));
28
42
  return internalDep(absolutePath, options);
@@ -30,18 +44,16 @@ function resolveRelativePath(importPath, fromFile, options) {
30
44
 
31
45
  // Resolve absolute paths pointing to the same app/addon as the importer
32
46
  function resolveLocalPath(importPath, fromFile, options) {
33
- let appOrAddonDirIndex = fromFile.indexOf(options.ownerName, options.root.length);
47
+ const fromFileStartsWithOwnerName = fromFile.substring(options.root.length + 1).startsWith(options.ownerName);
34
48
 
35
49
  // Depending on the exact version of Ember CLI and/or Embroider in play, the
36
50
  // app/addon name may or may not be included in `fromFile`'s path. If not, we
37
51
  // need to strip that prefix from the import path.
38
- if (appOrAddonDirIndex === -1) {
39
- appOrAddonDirIndex = options.root.length;
40
- importPath = ensurePosixPath(importPath).replace(new RegExp('^' + options.ownerName + '/?'), '');
52
+ if (!fromFileStartsWithOwnerName) {
53
+ importPath = importPath.substring(options.ownerName.length + 1);
41
54
  }
42
55
 
43
- let prefix = fromFile.substring(0, appOrAddonDirIndex);
44
- let absolutePath = ensurePosixPath(path.resolve(prefix, importPath));
56
+ let absolutePath = ensurePosixPath(path.resolve(options.root, importPath));
45
57
  return internalDep(absolutePath, options);
46
58
  }
47
59
 
@@ -49,7 +61,12 @@ function resolveLocalPath(importPath, fromFile, options) {
49
61
  function resolveExternalPath(importPath, originalPath, fromFile, options) {
50
62
  let baseIndex = importPath[0] === '@' ? importPath.indexOf('/') + 1 : 0;
51
63
  let addonName = importPath.substring(0, importPath.indexOf('/', baseIndex));
52
- let addon = options.parent.addons.find(addon => addon.name === addonName);
64
+ let addon = options.parent.addons.find((addon) => {
65
+ if (addon.moduleName) {
66
+ return addon.moduleName() === addonName;
67
+ }
68
+ return addon.name === addonName;
69
+ });
53
70
 
54
71
  if (!addon) {
55
72
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-css-modules",
3
- "version": "1.3.3",
3
+ "version": "1.6.0",
4
4
  "description": "CSS Modules for ambitious applications",
5
5
  "scripts": {
6
6
  "build": "ember build",
@@ -51,7 +51,7 @@
51
51
  "eslint-plugin-ember": "^5.2.0",
52
52
  "eslint-plugin-node": "^7.0.1",
53
53
  "loader.js": "^4.7.0",
54
- "postcss-color-rebeccapurple": "^3.0.0",
54
+ "postcss-color-rebeccapurple": "^6.0.0",
55
55
  "qunit-dom": "^0.7.1",
56
56
  "qunitjs": "^2.4.1",
57
57
  "sinon": "^4.3.0",
@@ -71,10 +71,10 @@
71
71
  "dependencies": {
72
72
  "broccoli-bridge": "^1.0.0",
73
73
  "broccoli-concat": "^3.2.2",
74
- "broccoli-css-modules": "^0.7.0",
74
+ "broccoli-css-modules": "^0.7.0 || ^0.8.0",
75
75
  "broccoli-funnel": "^2.0.1",
76
76
  "broccoli-merge-trees": "^2.0.0",
77
- "broccoli-postcss": "^4.0.1",
77
+ "broccoli-postcss": "^4.0.1 || ^5.0.0 || ^6.0.0",
78
78
  "calculate-cache-key-for-tree": "^1.1.0",
79
79
  "debug": "^3.1.0",
80
80
  "ember-cli-babel": "^7.7.3",
@@ -83,7 +83,7 @@
83
83
  "ensure-posix-path": "^1.0.2",
84
84
  "hash-string": "^1.0.0",
85
85
  "lodash.merge": "^4.6.1",
86
- "postcss": "^6.0.19",
86
+ "postcss": "^7.0.35 || ^8.0.0",
87
87
  "semver": "^5.5.0",
88
88
  "toposort": "^1.0.6"
89
89
  },