ember-scoped-css 1.1.0 → 2.0.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/README.md +203 -47
- package/dist/cjs/all-Du43cBa9.cjs +1308 -0
- package/dist/cjs/all.cjs +3 -0
- package/dist/cjs/babel.cjs +9 -0
- package/dist/cjs/rollup.cjs +8 -0
- package/dist/cjs/vite.cjs +8 -0
- package/dist/runtime/index.d.ts +11 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +12 -8
- package/dist/runtime/index.js.map +1 -7
- package/{declarations → dist}/runtime/test-support.d.ts +5 -2
- package/dist/runtime/test-support.d.ts.map +1 -0
- package/dist/runtime/test-support.js +357 -182
- package/dist/runtime/test-support.js.map +1 -7
- package/package.json +21 -24
- package/src/build/babel-plugin.js +4 -1
- package/src/build/public-exports/all.js +10 -0
- package/src/build/public-exports/babel.js +5 -0
- package/src/build/public-exports/rollup.js +3 -0
- package/src/build/public-exports/vite.js +3 -0
- package/src/build/scoped-css-unplugin.js +10 -33
- package/src/build/template-plugin.js +9 -19
- package/src/build/template-plugin.test.ts +108 -19
- package/src/build/unplugin-colocated.js +103 -0
- package/src/build/unplugin-inline.js +71 -0
- package/src/lib/css/rewrite.js +8 -8
- package/src/lib/css/rewrite.test.ts +69 -128
- package/src/lib/path/const.js +19 -0
- package/src/lib/path/hash-from-absolute-path.js +3 -2
- package/src/lib/path/template-transform-paths.js +3 -2
- package/src/lib/path/utils.appPath.test.ts +2 -2
- package/src/lib/path/utils.hashFrom.test.ts +2 -2
- package/src/lib/path/utils.js +63 -20
- package/src/lib/request.js +58 -33
- package/src/runtime/index.ts +1 -1
- package/declarations/build/template-plugin.d.ts +0 -7
- package/declarations/build/template-plugin.d.ts.map +0 -1
- package/declarations/build/template-plugin.test.d.ts +0 -2
- package/declarations/build/template-plugin.test.d.ts.map +0 -1
- package/declarations/lib/css/rewrite.d.ts +0 -2
- package/declarations/lib/css/rewrite.d.ts.map +0 -1
- package/declarations/lib/css/rewrite.test.d.ts +0 -2
- package/declarations/lib/css/rewrite.test.d.ts.map +0 -1
- package/declarations/lib/css/utils.d.ts +0 -29
- package/declarations/lib/css/utils.d.ts.map +0 -1
- package/declarations/lib/path/hash-from-absolute-path.d.ts +0 -3
- package/declarations/lib/path/hash-from-absolute-path.d.ts.map +0 -1
- package/declarations/lib/path/hash-from-absolute-path.test.d.ts +0 -2
- package/declarations/lib/path/hash-from-absolute-path.test.d.ts.map +0 -1
- package/declarations/lib/path/hash-from-module-path.d.ts +0 -31
- package/declarations/lib/path/hash-from-module-path.d.ts.map +0 -1
- package/declarations/lib/path/md5.d.ts +0 -12
- package/declarations/lib/path/md5.d.ts.map +0 -1
- package/declarations/lib/path/template-transform-paths.d.ts +0 -11
- package/declarations/lib/path/template-transform-paths.d.ts.map +0 -1
- package/declarations/lib/path/template-transform-paths.test.d.ts +0 -2
- package/declarations/lib/path/template-transform-paths.test.d.ts.map +0 -1
- package/declarations/lib/path/utils.appPath.test.d.ts +0 -2
- package/declarations/lib/path/utils.appPath.test.d.ts.map +0 -1
- package/declarations/lib/path/utils.d.ts +0 -94
- package/declarations/lib/path/utils.d.ts.map +0 -1
- package/declarations/lib/path/utils.findWorkspacePath.test.d.ts +0 -2
- package/declarations/lib/path/utils.findWorkspacePath.test.d.ts.map +0 -1
- package/declarations/lib/path/utils.hashFrom.test.d.ts +0 -2
- package/declarations/lib/path/utils.hashFrom.test.d.ts.map +0 -1
- package/declarations/lib/path/utils.isRelevantFile.test.d.ts +0 -2
- package/declarations/lib/path/utils.isRelevantFile.test.d.ts.map +0 -1
- package/declarations/lib/path/utils.paths.test.d.ts +0 -5
- package/declarations/lib/path/utils.paths.test.d.ts.map +0 -1
- package/declarations/lib/renameClass.d.ts +0 -9
- package/declarations/lib/renameClass.d.ts.map +0 -1
- package/declarations/lib/request.d.ts +0 -8
- package/declarations/lib/request.d.ts.map +0 -1
- package/declarations/lib/rewriteHbs.d.ts +0 -17
- package/declarations/lib/rewriteHbs.d.ts.map +0 -1
- package/declarations/runtime/index.d.ts +0 -8
- package/declarations/runtime/index.d.ts.map +0 -1
- package/declarations/runtime/test-support.d.ts.map +0 -1
- package/dist/cjs/babel-plugin.cjs +0 -176
- package/dist/cjs/index.cjs +0 -968
- package/dist/cjs/template-plugin.cjs +0 -856
- package/src/build/index.js +0 -7
- package/src/build/vite.js +0 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { rewriteCss } from '../lib/css/rewrite.js';
|
|
4
|
+
import { request } from '../lib/request.js';
|
|
5
|
+
|
|
6
|
+
const META = 'scoped-css:inline';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Plugin for supporting the styles from
|
|
10
|
+
*
|
|
11
|
+
* <template>
|
|
12
|
+
* <style>...</style>
|
|
13
|
+
* </template>
|
|
14
|
+
*
|
|
15
|
+
* This plugin can't have HMR for CSS because changes to the CSS content alters the template content
|
|
16
|
+
*/
|
|
17
|
+
export function inline(options = {}) {
|
|
18
|
+
const CWD = process.cwd();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} id the request id / what was imported
|
|
22
|
+
*/
|
|
23
|
+
function buildResponse(id, filePath) {
|
|
24
|
+
const parsed = request.inline.decode(id);
|
|
25
|
+
|
|
26
|
+
const relativeFilePath = path.relative(CWD, filePath);
|
|
27
|
+
|
|
28
|
+
const css = rewriteCss(
|
|
29
|
+
parsed.css,
|
|
30
|
+
parsed.postfix,
|
|
31
|
+
`<inline>/${relativeFilePath}`,
|
|
32
|
+
options.layerName,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const nextId = filePath.split('?')[0];
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
id: nextId,
|
|
39
|
+
meta: {
|
|
40
|
+
[META]: {
|
|
41
|
+
css,
|
|
42
|
+
postfix: parsed.postfix,
|
|
43
|
+
fileName: relativeFilePath,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
name: 'ember-scoped-css:inline',
|
|
51
|
+
resolveId(id, importer) {
|
|
52
|
+
if (request.is.inline(id)) {
|
|
53
|
+
const parsed = request.inline.decode(id);
|
|
54
|
+
|
|
55
|
+
const filePath = path.resolve(
|
|
56
|
+
path.dirname(importer),
|
|
57
|
+
`${path.basename(importer, path.extname(importer))}-${parsed.hash}.css`,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return buildResponse(id, filePath);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
load(id) {
|
|
64
|
+
const meta = this.getModuleInfo(id)?.meta?.[META];
|
|
65
|
+
|
|
66
|
+
if (meta) {
|
|
67
|
+
return meta.css;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
package/src/lib/css/rewrite.js
CHANGED
|
@@ -85,7 +85,6 @@ function isInsideKeyframes(node) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export function rewriteCss(css, postfix, fileName, layerName) {
|
|
88
|
-
const layerNameWithDefault = layerName ?? 'components';
|
|
89
88
|
const ast = postcss.parse(css);
|
|
90
89
|
/**
|
|
91
90
|
* kind => originalName => postfixedName
|
|
@@ -185,13 +184,14 @@ export function rewriteCss(css, postfix, fileName, layerName) {
|
|
|
185
184
|
|
|
186
185
|
const rewrittenCss = ast.toString();
|
|
187
186
|
|
|
188
|
-
if (!layerNameWithDefault) {
|
|
189
|
-
return `/* ${fileName} */\n${rewrittenCss}\n`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
187
|
return (
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
188
|
+
[
|
|
189
|
+
`/* ${fileName} */`,
|
|
190
|
+
layerName ? `@layer ${layerName} {` : '',
|
|
191
|
+
rewrittenCss.trimEnd(),
|
|
192
|
+
layerName ? `}` : '',
|
|
193
|
+
]
|
|
194
|
+
.filter(Boolean)
|
|
195
|
+
.join('\n') + '\n'
|
|
196
196
|
);
|
|
197
197
|
}
|
|
@@ -6,7 +6,7 @@ it('should rewrite css', function () {
|
|
|
6
6
|
const css = '.foo { color: red; }';
|
|
7
7
|
const postfix = 'postfix';
|
|
8
8
|
const fileName = 'foo.css';
|
|
9
|
-
const rewritten = rewriteCss(css, postfix, fileName
|
|
9
|
+
const rewritten = rewriteCss(css, postfix, fileName);
|
|
10
10
|
|
|
11
11
|
expect(rewritten).to.equal(`/* foo.css */\n.foo_postfix { color: red; }\n`);
|
|
12
12
|
});
|
|
@@ -17,20 +17,12 @@ it('should use a custom layer', function () {
|
|
|
17
17
|
const fileName = 'foo.css';
|
|
18
18
|
const rewritten = rewriteCss(css, postfix, fileName, 'utils');
|
|
19
19
|
|
|
20
|
-
expect(rewritten).
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const css = '.baz :global(.foo p) .bar { color: red; }';
|
|
27
|
-
const postfix = 'postfix';
|
|
28
|
-
const fileName = 'foo.css';
|
|
29
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
30
|
-
|
|
31
|
-
expect(rewritten).to.equal(
|
|
32
|
-
`/* foo.css */\n@layer components {\n\n.baz_postfix .foo p .bar_postfix { color: red; }\n}\n`,
|
|
33
|
-
);
|
|
20
|
+
expect(rewritten).toMatchInlineSnapshot(`
|
|
21
|
+
"/* foo.css */
|
|
22
|
+
@layer utils {
|
|
23
|
+
.foo_postfix { color: red; }
|
|
24
|
+
}
|
|
25
|
+
"`);
|
|
34
26
|
});
|
|
35
27
|
|
|
36
28
|
it(`understands nth-of-type syntax`, function () {
|
|
@@ -45,15 +37,10 @@ it(`understands nth-of-type syntax`, function () {
|
|
|
45
37
|
|
|
46
38
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
47
39
|
"/* foo.css */
|
|
48
|
-
@layer components {
|
|
49
|
-
|
|
50
40
|
|
|
51
41
|
li.postfix:nth-of-type(odd) {}
|
|
52
42
|
li.postfix:nth-of-type(even) {}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
"
|
|
56
|
-
`);
|
|
43
|
+
"`);
|
|
57
44
|
});
|
|
58
45
|
|
|
59
46
|
describe('@container', () => {
|
|
@@ -71,18 +58,13 @@ describe('@container', () => {
|
|
|
71
58
|
|
|
72
59
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
73
60
|
"/* foo.css */
|
|
74
|
-
@layer components {
|
|
75
|
-
|
|
76
61
|
|
|
77
62
|
@container (width > 400px) {
|
|
78
63
|
h2.postfix {
|
|
79
64
|
font-size: 1.5em;
|
|
80
65
|
}
|
|
81
66
|
}
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
"
|
|
85
|
-
`);
|
|
67
|
+
"`);
|
|
86
68
|
});
|
|
87
69
|
|
|
88
70
|
it('handles parameters', () => {
|
|
@@ -116,8 +98,6 @@ describe('@container', () => {
|
|
|
116
98
|
|
|
117
99
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
118
100
|
"/* foo.css */
|
|
119
|
-
@layer components {
|
|
120
|
-
|
|
121
101
|
|
|
122
102
|
/* With an optional <container-name> */
|
|
123
103
|
@container tall (height > 30rem) {
|
|
@@ -140,10 +120,7 @@ describe('@container', () => {
|
|
|
140
120
|
color: white;
|
|
141
121
|
}
|
|
142
122
|
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
"
|
|
146
|
-
`);
|
|
123
|
+
"`);
|
|
147
124
|
});
|
|
148
125
|
});
|
|
149
126
|
|
|
@@ -162,14 +139,11 @@ describe('@media', () => {
|
|
|
162
139
|
"/* foo.css */
|
|
163
140
|
@layer utils {
|
|
164
141
|
|
|
165
|
-
|
|
166
142
|
@media (height >= 680px), screen and (orientation: portrait) {
|
|
167
143
|
.foo_postfix { color: red; }
|
|
168
144
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
"
|
|
172
|
-
`);
|
|
145
|
+
}
|
|
146
|
+
"`);
|
|
173
147
|
});
|
|
174
148
|
});
|
|
175
149
|
|
|
@@ -185,22 +159,19 @@ describe('@keyframe', () => {
|
|
|
185
159
|
|
|
186
160
|
const postfix = 'postfix';
|
|
187
161
|
const fileName = 'foo.css';
|
|
188
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
162
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
189
163
|
|
|
190
164
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
191
165
|
"/* foo.css */
|
|
192
166
|
@layer components {
|
|
193
167
|
|
|
194
|
-
|
|
195
168
|
@keyframes luna-view-navigation__postfix {
|
|
196
169
|
100% {
|
|
197
170
|
padding-top: 1rem;
|
|
198
171
|
}
|
|
199
172
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
"
|
|
203
|
-
`);
|
|
173
|
+
}
|
|
174
|
+
"`);
|
|
204
175
|
});
|
|
205
176
|
|
|
206
177
|
it(`references are also scoped`, function () {
|
|
@@ -225,12 +196,11 @@ describe('@keyframe', () => {
|
|
|
225
196
|
|
|
226
197
|
const postfix = 'postfix';
|
|
227
198
|
const fileName = 'foo.css';
|
|
228
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
199
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
229
200
|
|
|
230
201
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
231
202
|
"/* foo.css */
|
|
232
|
-
|
|
233
|
-
|
|
203
|
+
@layer components {
|
|
234
204
|
|
|
235
205
|
p.postfix {
|
|
236
206
|
animation-duration: 3s;
|
|
@@ -248,10 +218,8 @@ describe('@keyframe', () => {
|
|
|
248
218
|
scale: 100% 1;
|
|
249
219
|
}
|
|
250
220
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
"
|
|
254
|
-
`);
|
|
221
|
+
}
|
|
222
|
+
"`);
|
|
255
223
|
});
|
|
256
224
|
|
|
257
225
|
it('handles multiple references and keyframes', () => {
|
|
@@ -296,12 +264,11 @@ describe('@keyframe', () => {
|
|
|
296
264
|
`;
|
|
297
265
|
const postfix = 'postfix';
|
|
298
266
|
const fileName = 'foo.css';
|
|
299
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
267
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
300
268
|
|
|
301
269
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
302
270
|
"/* foo.css */
|
|
303
|
-
|
|
304
|
-
|
|
271
|
+
@layer components {
|
|
305
272
|
|
|
306
273
|
p.postfix {
|
|
307
274
|
animation-duration: 3s;
|
|
@@ -340,10 +307,8 @@ describe('@keyframe', () => {
|
|
|
340
307
|
color: magenta;
|
|
341
308
|
}
|
|
342
309
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
"
|
|
346
|
-
`);
|
|
310
|
+
}
|
|
311
|
+
"`);
|
|
347
312
|
});
|
|
348
313
|
|
|
349
314
|
it('works in shorthand combo-declarations', () => {
|
|
@@ -364,12 +329,11 @@ describe('@keyframe', () => {
|
|
|
364
329
|
|
|
365
330
|
const postfix = 'postfix';
|
|
366
331
|
const fileName = 'foo.css';
|
|
367
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
332
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
368
333
|
|
|
369
334
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
370
335
|
"/* foo.css */
|
|
371
|
-
|
|
372
|
-
|
|
336
|
+
@layer components {
|
|
373
337
|
|
|
374
338
|
div.postfix {
|
|
375
339
|
width: 100px;
|
|
@@ -383,10 +347,8 @@ describe('@keyframe', () => {
|
|
|
383
347
|
from {top: 0px;}
|
|
384
348
|
to {top: 200px;}
|
|
385
349
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
"
|
|
389
|
-
`);
|
|
350
|
+
}
|
|
351
|
+
"`);
|
|
390
352
|
});
|
|
391
353
|
});
|
|
392
354
|
|
|
@@ -402,22 +364,19 @@ describe('@counter-style', () => {
|
|
|
402
364
|
|
|
403
365
|
const postfix = 'postfix';
|
|
404
366
|
const fileName = 'foo.css';
|
|
405
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
367
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
406
368
|
|
|
407
369
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
408
370
|
"/* foo.css */
|
|
409
371
|
@layer components {
|
|
410
372
|
|
|
411
|
-
|
|
412
373
|
@counter-style circled-alpha__postfix {
|
|
413
374
|
system: fixed;
|
|
414
375
|
symbols: Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ;
|
|
415
376
|
suffix: " ";
|
|
416
377
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
"
|
|
420
|
-
`);
|
|
378
|
+
}
|
|
379
|
+
"`);
|
|
421
380
|
});
|
|
422
381
|
|
|
423
382
|
it('updates references', () => {
|
|
@@ -435,26 +394,23 @@ describe('@counter-style', () => {
|
|
|
435
394
|
|
|
436
395
|
const postfix = 'postfix';
|
|
437
396
|
const fileName = 'foo.css';
|
|
438
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
397
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
439
398
|
|
|
440
399
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
441
400
|
"/* foo.css */
|
|
442
|
-
|
|
443
|
-
|
|
401
|
+
@layer components {
|
|
444
402
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
403
|
+
@counter-style circled-alpha__postfix {
|
|
404
|
+
system: fixed;
|
|
405
|
+
symbols: Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ;
|
|
406
|
+
suffix: " ";
|
|
407
|
+
}
|
|
450
408
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
"
|
|
457
|
-
`);
|
|
409
|
+
.items_postfix {
|
|
410
|
+
list-style: circled-alpha__postfix;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
"`);
|
|
458
414
|
});
|
|
459
415
|
});
|
|
460
416
|
|
|
@@ -470,22 +426,19 @@ describe('@position-try', () => {
|
|
|
470
426
|
|
|
471
427
|
const postfix = 'postfix';
|
|
472
428
|
const fileName = 'foo.css';
|
|
473
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
429
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
474
430
|
|
|
475
431
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
476
432
|
"/* foo.css */
|
|
477
|
-
|
|
478
|
-
|
|
433
|
+
@layer components {
|
|
479
434
|
|
|
480
435
|
@position-try --custom-left__postfix {
|
|
481
436
|
position-area: left;
|
|
482
437
|
width: 100px;
|
|
483
438
|
margin-right: 10px;
|
|
484
439
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
"
|
|
488
|
-
`);
|
|
440
|
+
}
|
|
441
|
+
"`);
|
|
489
442
|
});
|
|
490
443
|
|
|
491
444
|
it('updates references', () => {
|
|
@@ -504,27 +457,24 @@ describe('@position-try', () => {
|
|
|
504
457
|
|
|
505
458
|
const postfix = 'postfix';
|
|
506
459
|
const fileName = 'foo.css';
|
|
507
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
460
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
508
461
|
|
|
509
462
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
510
463
|
"/* foo.css */
|
|
511
|
-
|
|
512
|
-
|
|
464
|
+
@layer components {
|
|
513
465
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
466
|
+
@position-try --custom-left__postfix {
|
|
467
|
+
position-area: left;
|
|
468
|
+
width: 100px;
|
|
469
|
+
margin-right: 10px;
|
|
470
|
+
}
|
|
519
471
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
"
|
|
527
|
-
`);
|
|
472
|
+
.infobox_postfix {
|
|
473
|
+
position-try-fallbacks:
|
|
474
|
+
--custom-left__postfix;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
"`);
|
|
528
478
|
});
|
|
529
479
|
});
|
|
530
480
|
|
|
@@ -540,22 +490,19 @@ describe('@property', () => {
|
|
|
540
490
|
|
|
541
491
|
const postfix = 'postfix';
|
|
542
492
|
const fileName = 'foo.css';
|
|
543
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
493
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
544
494
|
|
|
545
495
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
546
496
|
"/* foo.css */
|
|
547
|
-
|
|
548
|
-
|
|
497
|
+
@layer components {
|
|
549
498
|
|
|
550
499
|
@property --item-size__postfix {
|
|
551
500
|
syntax: "<percentage>";
|
|
552
501
|
inherits: true;
|
|
553
502
|
initial-value: 40%;
|
|
554
503
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
"
|
|
558
|
-
`);
|
|
504
|
+
}
|
|
505
|
+
"`);
|
|
559
506
|
});
|
|
560
507
|
|
|
561
508
|
it('updates references', () => {
|
|
@@ -586,12 +533,11 @@ describe('@property', () => {
|
|
|
586
533
|
|
|
587
534
|
const postfix = 'postfix';
|
|
588
535
|
const fileName = 'foo.css';
|
|
589
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
536
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
590
537
|
|
|
591
538
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
592
539
|
"/* foo.css */
|
|
593
|
-
|
|
594
|
-
|
|
540
|
+
@layer components {
|
|
595
541
|
|
|
596
542
|
@property --item-size__postfix {
|
|
597
543
|
syntax: "<percentage>";
|
|
@@ -615,10 +561,8 @@ describe('@property', () => {
|
|
|
615
561
|
height: var(--item-size__postfix);
|
|
616
562
|
background-color: var(--item-color);
|
|
617
563
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
"
|
|
621
|
-
`);
|
|
564
|
+
}
|
|
565
|
+
"`);
|
|
622
566
|
});
|
|
623
567
|
});
|
|
624
568
|
|
|
@@ -631,18 +575,15 @@ describe('@supports', () => {
|
|
|
631
575
|
|
|
632
576
|
const postfix = 'postfix';
|
|
633
577
|
const fileName = 'foo.css';
|
|
634
|
-
const rewritten = rewriteCss(css, postfix, fileName);
|
|
578
|
+
const rewritten = rewriteCss(css, postfix, fileName, 'components');
|
|
635
579
|
|
|
636
580
|
expect(rewritten).toMatchInlineSnapshot(`
|
|
637
581
|
"/* foo.css */
|
|
638
582
|
@layer components {
|
|
639
583
|
|
|
640
|
-
|
|
641
584
|
@supports (transform-origin: 5% 5%) {}
|
|
642
585
|
@supports selector(h2 > p) {}
|
|
643
|
-
|
|
644
586
|
}
|
|
645
|
-
|
|
646
|
-
`);
|
|
587
|
+
"`);
|
|
647
588
|
});
|
|
648
589
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Join will convert to whatever is appropriate fro the current platform
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const leadingSlashPath = {
|
|
8
|
+
embroiderDir: path.join('/node_modules/.embroider/'),
|
|
9
|
+
atEmbroider: path.join('/@embroider'),
|
|
10
|
+
componentsDir: path.join('/components/'),
|
|
11
|
+
templatesDir: path.join('/templates/'),
|
|
12
|
+
testem: path.join('/testem'),
|
|
13
|
+
src: path.join('/src/'),
|
|
14
|
+
app: path.join('/app/'),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const barePath = {
|
|
18
|
+
pnpmDir: path.join('node_modules/.pnpm'),
|
|
19
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hash } from './hash-from-module-path.js';
|
|
2
|
-
import { appPath } from './utils.js';
|
|
2
|
+
import { appPath, forcePosix } from './utils.js';
|
|
3
3
|
|
|
4
4
|
export { hash } from './hash-from-module-path.js';
|
|
5
5
|
|
|
@@ -10,7 +10,8 @@ export function hashFromAbsolutePath(absolutePath) {
|
|
|
10
10
|
* at runtime.
|
|
11
11
|
*/
|
|
12
12
|
const modulePath = appPath(absolutePath);
|
|
13
|
-
const
|
|
13
|
+
const forced = forcePosix(modulePath);
|
|
14
|
+
const postfix = hash(forced);
|
|
14
15
|
|
|
15
16
|
return postfix;
|
|
16
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
|
+
import { leadingSlashPath } from './const.js';
|
|
3
4
|
import { findWorkspacePath } from './utils.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -28,10 +29,10 @@ export function fixFilename(filename) {
|
|
|
28
29
|
|
|
29
30
|
if (
|
|
30
31
|
!(hasAppDir || hasSrcDir) &&
|
|
31
|
-
!fileName.includes(
|
|
32
|
+
!fileName.includes(leadingSlashPath.embroiderDir)
|
|
32
33
|
) {
|
|
33
34
|
let maybeModule = fileName.replace(workspace, '');
|
|
34
|
-
let [maybeScope, ...rest] = maybeModule.split(
|
|
35
|
+
let [maybeScope, ...rest] = maybeModule.split(path.sep).filter(Boolean);
|
|
35
36
|
let parts = rest;
|
|
36
37
|
|
|
37
38
|
if (maybeScope.startsWith('@')) {
|
|
@@ -10,13 +10,13 @@ describe('appPath()', () => {
|
|
|
10
10
|
let file = path.join(paths.viteApp, 'app', 'templates/application');
|
|
11
11
|
let result = appPath(file);
|
|
12
12
|
|
|
13
|
-
expect(result).to.equal('vite-app/templates/application');
|
|
13
|
+
expect(result).to.equal(path.join('vite-app/templates/application'));
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it('handles psuedo module', () => {
|
|
17
17
|
let file = path.join(paths.viteApp, 'templates/application');
|
|
18
18
|
let result = appPath(file);
|
|
19
19
|
|
|
20
|
-
expect(result).to.equal('vite-app/templates/application');
|
|
20
|
+
expect(result).to.equal(path.join('vite-app/templates/application'));
|
|
21
21
|
});
|
|
22
22
|
});
|
|
@@ -10,13 +10,13 @@ describe('hashFrom()', () => {
|
|
|
10
10
|
css: path.join(paths.viteApp, 'components/forth.css'),
|
|
11
11
|
ext: path.join(paths.viteApp, 'components/forth.gjs'),
|
|
12
12
|
withoutExt: path.join(paths.viteApp, 'components/forth'),
|
|
13
|
-
module: 'vite-app/components/forth',
|
|
13
|
+
module: path.join('vite-app/components/forth'),
|
|
14
14
|
};
|
|
15
15
|
let route = {
|
|
16
16
|
css: path.join(paths.viteApp, 'templates/application.css'),
|
|
17
17
|
ext: path.join(paths.viteApp, 'templates/application.gjs'),
|
|
18
18
|
withoutExt: path.join(paths.viteApp, 'templates/application'),
|
|
19
|
-
module: 'vite-app/templates/application',
|
|
19
|
+
module: path.join('vite-app/templates/application'),
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
describe('component', () => {
|