ember-scoped-css 2.0.3 → 2.1.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.
package/dist/cjs/all.cjs CHANGED
@@ -1,3 +1,3 @@
1
- const require_all = require('./all-CfBAmXua.cjs');
1
+ const require_all = require('./all-Bimr-GZ4.cjs');
2
2
 
3
3
  exports.scopedCSS = require_all.scopedCSS;
@@ -1,4 +1,4 @@
1
- const require_all = require('./all-CfBAmXua.cjs');
1
+ const require_all = require('./all-Bimr-GZ4.cjs');
2
2
 
3
3
  //#region src/build/public-exports/babel.js
4
4
  const scopedCSS = require_all.scopedCSS.babel;
@@ -1,4 +1,4 @@
1
- const require_all = require('./all-CfBAmXua.cjs');
1
+ const require_all = require('./all-Bimr-GZ4.cjs');
2
2
 
3
3
  //#region src/build/public-exports/rollup.js
4
4
  const scopedCSS = require_all.scopedCSS.rollup;
package/dist/cjs/vite.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_all = require('./all-CfBAmXua.cjs');
1
+ const require_all = require('./all-Bimr-GZ4.cjs');
2
2
 
3
3
  //#region src/build/public-exports/vite.js
4
4
  const scopedCSS = require_all.scopedCSS.vite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-scoped-css",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -1,4 +1,9 @@
1
- import { isRelevantFile } from '../lib/path/utils.js';
1
+ import {
2
+ appPath,
3
+ hashFromModulePath,
4
+ isRelevantFile,
5
+ } from '../lib/path/utils.js';
6
+ import { renameClass } from '../lib/renameClass.js';
2
7
 
3
8
  function _isRelevantFile(state, cwd) {
4
9
  let fileName = state.file.opts.filename;
@@ -34,6 +39,10 @@ export const scopedCSS = (config) => (env, options, workingDirectory) => {
34
39
 
35
40
  return;
36
41
  }
42
+
43
+ let modulePath = appPath(state.filename);
44
+
45
+ state.postfix = hashFromModulePath(modulePath);
37
46
  },
38
47
  },
39
48
  ImportDeclaration(path, state) {
@@ -59,6 +68,38 @@ export const scopedCSS = (config) => (env, options, workingDirectory) => {
59
68
  path.remove();
60
69
  }
61
70
  },
71
+ /**
72
+ * Rename usages in JS/TS/GJS/GTS
73
+ */
74
+ CallExpression(path, state) {
75
+ if (state.canSkip) {
76
+ return;
77
+ }
78
+
79
+ if (
80
+ path.node.callee.type === 'Identifier' &&
81
+ path.node.callee.name === state.file.opts?.importedScopedClass
82
+ ) {
83
+ if (
84
+ path.node.arguments.length !== 1 ||
85
+ path.node.arguments[0].type !== 'StringLiteral'
86
+ ) {
87
+ throw new Error(
88
+ `The scopedClass helper only accepts a single, non-dynamic, string literal argument.`,
89
+ );
90
+ }
91
+
92
+ const original = path.node.arguments[0].value;
93
+ const renamed = renameClass(
94
+ original,
95
+ state.postfix,
96
+ new Set([original]),
97
+ );
98
+ const transformedString = env.types.stringLiteral(renamed);
99
+
100
+ path.replaceWith(transformedString);
101
+ }
102
+ },
62
103
  /**
63
104
  * Only in strict mode, do we care about remoning the scope bag reference
64
105
  */
@@ -51,11 +51,6 @@ export function colocated(options = {}) {
51
51
  path.basename(parsed.fileName),
52
52
  );
53
53
 
54
- /**
55
- * Rollup doesn't normally watch CSS files
56
- */
57
- this.addWatchFile(filePath);
58
-
59
54
  return buildResponse(id, filePath);
60
55
  }
61
56
  },
@@ -63,6 +58,8 @@ export function colocated(options = {}) {
63
58
  const meta = this.getModuleInfo(id)?.meta?.[META];
64
59
 
65
60
  if (meta) {
61
+ this.addWatchFile(meta.fullPath);
62
+
66
63
  let code = readFileSync(meta.fullPath, 'utf-8');
67
64
 
68
65
  let css = rewriteCss(
@@ -9,6 +9,7 @@ export const leadingSlashPath = {
9
9
  atEmbroider: path.join('/@embroider'),
10
10
  componentsDir: path.join('/components/'),
11
11
  templatesDir: path.join('/templates/'),
12
+ routesDir: path.join('/routes/'),
12
13
  testem: path.join('/testem'),
13
14
  src: path.join('/src/'),
14
15
  app: path.join('/app/'),
@@ -20,6 +20,13 @@ describe('isRelevantFile()', () => {
20
20
 
21
21
  expect(result).toBeTruthy();
22
22
  });
23
+
24
+ it('for /routes/', () => {
25
+ let file = path.join(paths.viteApp, 'app/routes/application.gts');
26
+ let result = isRelevantFile(file, { cwd: paths.viteApp });
27
+
28
+ expect(result).toBeTruthy();
29
+ });
23
30
  });
24
31
 
25
32
  describe('the file is not relevant', () => {
@@ -259,6 +259,7 @@ export function isRelevantFile(fileName, { additionalRoots, cwd }) {
259
259
  let roots = [
260
260
  leadingSlashPath.componentsDir,
261
261
  leadingSlashPath.templatesDir,
262
+ leadingSlashPath.routesDir,
262
263
  ...(additionalRoots || []),
263
264
  ];
264
265