ember-scoped-css 0.9.0 → 0.10.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/LICENSE.md +9 -0
- package/addon-main.cjs +5 -0
- package/package.json +44 -41
- package/src/{app-css-livereload-loader.js → build/app-css-livereload-loader.js} +11 -3
- package/src/{app-css-loader.js → build/app-css-loader.js} +8 -6
- package/src/{app-dependency-loader.js → build/app-dependency-loader.js} +2 -1
- package/src/{app-js-unplugin.js → build/app-js-unplugin.js} +11 -4
- package/src/{app-scopedcss-webpack.js → build/app-scopedcss-webpack.js} +8 -4
- package/src/build/index.js +11 -0
- package/src/{scoped-css-unplugin.js → build/scoped-css-unplugin.js} +14 -7
- package/src/lib/findCssInJs.js +2 -0
- package/src/lib/fsExists.js +1 -0
- package/src/lib/generateAbsolutePathHash.js +93 -4
- package/src/lib/generateRelativePathHash.js +1 -1
- package/src/lib/getClassesTagsFromCss.js +2 -0
- package/src/lib/getFiles.js +1 -0
- package/src/lib/getImportedCssFiles.js +1 -0
- package/src/lib/isInsideGlobal.js +2 -0
- package/src/lib/renameClass.js +2 -1
- package/src/lib/replaceGlimmerAst.js +9 -2
- package/src/lib/replaceHbsInJs.js +5 -1
- package/src/lib/rewriteCss.js +7 -1
- package/src/lib/rewriteHbs.js +8 -0
- package/src/lib/scoped-css-preprocessor.js +7 -2
- package/src/{scopedClass.js → runtime/test-support.js} +2 -2
- package/src/scoped-babel-plugin.js +7 -3
- package/src/template-lint/plugin.js +1 -0
- package/.eslintignore +0 -8
- package/.eslintrc.cjs +0 -37
- package/dist/app-css-loader.cjs +0 -9743
- package/dist/app-dependency-loader.cjs +0 -51
- package/dist/lib/scoped-css-preprocessor.cjs +0 -41943
- package/dist/scoped-babel-plugin.cjs +0 -22870
- package/index.js +0 -11
- package/src/ember-addon-main.cjs +0 -48
- package/test/generateHash.js +0 -22
- package/test/getClassesTagsFromCss.js +0 -15
- package/test/rewriteCss.js +0 -44
- package/test/template-lint-rule.js +0 -38
- /package/src/{app-css-unplugin.js → build/app-css-unplugin.js} +0 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/addon-main.cjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-scoped-css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -8,29 +8,33 @@
|
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"author": "",
|
|
10
10
|
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"addon-main.cjs"
|
|
14
|
+
],
|
|
11
15
|
"exports": {
|
|
12
|
-
"
|
|
13
|
-
"./
|
|
14
|
-
"./
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
16
|
+
"./test-support": "./src/runtime/test-support.js",
|
|
17
|
+
"./build": "./src/build/index.js",
|
|
18
|
+
"./build/app-css-loader": {
|
|
19
|
+
"import": "./src/build/app-css-loader.js",
|
|
20
|
+
"require": "./dist/build/app-css-loader.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./build/app-dependency-loader": {
|
|
23
|
+
"import": "./src/build/app-dependency-loader.js",
|
|
24
|
+
"require": "./dist/build/app-dependency-loader.cjs"
|
|
18
25
|
},
|
|
19
|
-
"./
|
|
20
|
-
"
|
|
21
|
-
|
|
26
|
+
"./build/ember-classic-support": {
|
|
27
|
+
"require": "./dist/lib/scoped-css-preprocessor.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./addon-main.cjs": "./addon-main.cjs",
|
|
30
|
+
"./babel-plugin": {
|
|
31
|
+
"import": "./src/scoped-babel-plugin.js",
|
|
32
|
+
"require": "./dist/scoped-babel-plugin.cjs"
|
|
22
33
|
}
|
|
23
34
|
},
|
|
24
|
-
"main": "index.js",
|
|
25
|
-
"scripts": {
|
|
26
|
-
"esbuild": "esbuild src/scoped-babel-plugin.js src/app-css-loader.js src/app-dependency-loader.js src/lib/scoped-css-preprocessor.js --bundle --outdir=dist --platform=node --out-extension:.js=.cjs",
|
|
27
|
-
"lint": "eslint .",
|
|
28
|
-
"prepare": "npm run esbuild",
|
|
29
|
-
"release": "npx release-it",
|
|
30
|
-
"test": "mocha"
|
|
31
|
-
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@babel/parser": "^7.21.4",
|
|
37
|
+
"@embroider/addon-shim": "^1.0.0",
|
|
34
38
|
"blueimp-md5": "^2.19.0",
|
|
35
39
|
"broccoli-concat": "^4.2.5",
|
|
36
40
|
"broccoli-funnel": "^3.0.8",
|
|
@@ -41,6 +45,7 @@
|
|
|
41
45
|
"ember-cli-babel": "^7.26.11",
|
|
42
46
|
"ember-source": "^4.10.0",
|
|
43
47
|
"ember-template-recast": "^6.1.3",
|
|
48
|
+
"find-up": "^6.3.0",
|
|
44
49
|
"glob": "^8.1.0",
|
|
45
50
|
"postcss": "^8.4.21",
|
|
46
51
|
"postcss-selector-parser": "^6.0.11",
|
|
@@ -49,22 +54,25 @@
|
|
|
49
54
|
"unplugin": "^1.0.1"
|
|
50
55
|
},
|
|
51
56
|
"devDependencies": {
|
|
57
|
+
"@babel/eslint-parser": "^7.22.5",
|
|
58
|
+
"@nullvoxpopuli/eslint-configs": "^3.1.3",
|
|
52
59
|
"chai": "^4.3.7",
|
|
60
|
+
"concurrently": "^8.2.0",
|
|
61
|
+
"ember-template-lint": "^5.7.2",
|
|
53
62
|
"esbuild": "^0.17.17",
|
|
54
63
|
"eslint": "^8.38.0",
|
|
55
|
-
"ember-template-lint": "^5.7.2",
|
|
56
64
|
"mocha": "^10.2.0",
|
|
57
|
-
"
|
|
58
|
-
"release-it-lerna-changelog": "^5.0.0",
|
|
65
|
+
"prettier": "^2.8.8",
|
|
59
66
|
"sinon": "^15.0.1",
|
|
60
67
|
"webpack": "^5.75.0"
|
|
61
68
|
},
|
|
62
69
|
"ember-addon": {
|
|
63
|
-
"main": "
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
"main": "addon-main.cjs",
|
|
71
|
+
"type": "addon",
|
|
72
|
+
"version": 2
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">= 18"
|
|
68
76
|
},
|
|
69
77
|
"peerDependencies": {
|
|
70
78
|
"ember-template-lint": "^5.7.2",
|
|
@@ -78,19 +86,14 @@
|
|
|
78
86
|
"publishConfig": {
|
|
79
87
|
"registry": "https://registry.npmjs.org"
|
|
80
88
|
},
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
},
|
|
91
|
-
"github": {
|
|
92
|
-
"release": true,
|
|
93
|
-
"tokenRef": "GITHUB_AUTH"
|
|
94
|
-
}
|
|
89
|
+
"scripts": {
|
|
90
|
+
"build": "esbuild src/scoped-babel-plugin.js src/build/app-css-loader.js src/build/app-dependency-loader.js src/lib/scoped-css-preprocessor.js src/runtime/test-support.js --bundle --outdir=dist --platform=node --out-extension:.js=.cjs",
|
|
91
|
+
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
|
|
92
|
+
"lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
|
|
93
|
+
"lint:js": "eslint .",
|
|
94
|
+
"lint:js:fix": "eslint . --fix",
|
|
95
|
+
"lint:prettier:fix": "prettier . -w",
|
|
96
|
+
"lint:prettier": "prettier . -c",
|
|
97
|
+
"test": "mocha"
|
|
95
98
|
}
|
|
96
|
-
}
|
|
99
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createUnplugin } from 'unplugin';
|
|
2
|
-
import path from 'path';
|
|
3
1
|
import { readFile } from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { createUnplugin } from 'unplugin';
|
|
4
4
|
import { Compilation } from 'webpack';
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
import generateHash from '../lib/generateAbsolutePathHash.js';
|
|
6
7
|
|
|
7
8
|
export default createUnplugin(({ loaders, htmlEntrypointInfo }) => {
|
|
8
9
|
return {
|
|
@@ -20,10 +21,12 @@ export default createUnplugin(({ loaders, htmlEntrypointInfo }) => {
|
|
|
20
21
|
const importRegex = /import\s+['"]([^'"]+\.css)['"]\s*;$/gm;
|
|
21
22
|
let cssPaths = [];
|
|
22
23
|
let match;
|
|
24
|
+
|
|
23
25
|
while ((match = importRegex.exec(code))) {
|
|
24
26
|
const importPath = match[1];
|
|
25
27
|
const directory = path.dirname(jsPath);
|
|
26
28
|
const cssPath = path.resolve(directory, importPath);
|
|
29
|
+
|
|
27
30
|
cssPaths.push(cssPath);
|
|
28
31
|
|
|
29
32
|
// replace import with empty string
|
|
@@ -36,10 +39,13 @@ export default createUnplugin(({ loaders, htmlEntrypointInfo }) => {
|
|
|
36
39
|
|
|
37
40
|
const promises = cssPaths.map(async (cssPath) => {
|
|
38
41
|
let css = await readFile(cssPath, 'utf8');
|
|
42
|
+
|
|
39
43
|
for (let i = loaders.length - 1; i >= 0; i--) {
|
|
40
44
|
const loader = loaders[i];
|
|
45
|
+
|
|
41
46
|
css = await loader.bind({ resourcePath: cssPath })(css);
|
|
42
47
|
}
|
|
48
|
+
|
|
43
49
|
// random string; lenght is 8
|
|
44
50
|
const postfix = generateHash(path.basename(cssPath));
|
|
45
51
|
|
|
@@ -76,6 +82,7 @@ export default createUnplugin(({ loaders, htmlEntrypointInfo }) => {
|
|
|
76
82
|
if (!cssAssets.length) {
|
|
77
83
|
return;
|
|
78
84
|
}
|
|
85
|
+
|
|
79
86
|
// let linkAdded = false;
|
|
80
87
|
const document =
|
|
81
88
|
htmlEntrypointInfo.htmlEntryPoint.dom.window.document;
|
|
@@ -88,6 +95,7 @@ export default createUnplugin(({ loaders, htmlEntrypointInfo }) => {
|
|
|
88
95
|
|
|
89
96
|
if (!linkExists) {
|
|
90
97
|
const link = document.createElement('link');
|
|
98
|
+
|
|
91
99
|
link.rel = 'stylesheet';
|
|
92
100
|
link.href = '/' + asset;
|
|
93
101
|
head.appendChild(link);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// import { createUnplugin } from 'unplugin';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import fsExists from '../lib/fsExists.js';
|
|
5
|
+
import generateHash from '../lib/generateAbsolutePathHash.js';
|
|
6
|
+
import rewriteCss from '../lib/rewriteCss.js';
|
|
7
7
|
|
|
8
8
|
export default async function (code) {
|
|
9
9
|
const cssPath = this.resourcePath;
|
|
10
|
-
const cssFileName = basename(cssPath);
|
|
10
|
+
const cssFileName = path.basename(cssPath);
|
|
11
|
+
|
|
11
12
|
const postfix = generateHash(cssPath);
|
|
12
13
|
|
|
13
14
|
const hbsPath = cssPath.replace('.css', '.hbs');
|
|
@@ -18,6 +19,7 @@ export default async function (code) {
|
|
|
18
19
|
]);
|
|
19
20
|
|
|
20
21
|
let rewrittenCss;
|
|
22
|
+
|
|
21
23
|
if (hbsExists || (gjsExists && cssPath.startsWith(this.rootContext))) {
|
|
22
24
|
rewrittenCss = rewriteCss(code, postfix, cssFileName);
|
|
23
25
|
} else {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import fsExists from '
|
|
1
|
+
import fsExists from '../lib/fsExists.js';
|
|
2
2
|
|
|
3
3
|
export default async function (source) {
|
|
4
4
|
if (this.resourcePath.endsWith('.js')) {
|
|
5
5
|
const hbsExists = await fsExists(this.resourcePath.replace(/\.js/, '.hbs'));
|
|
6
|
+
|
|
6
7
|
if (hbsExists) {
|
|
7
8
|
return source;
|
|
8
9
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createUnplugin } from 'unplugin';
|
|
2
|
-
import replaceGlimmerAst from './lib/replaceGlimmerAst.js';
|
|
3
1
|
import path from 'path';
|
|
4
|
-
import
|
|
5
|
-
|
|
2
|
+
import { createUnplugin } from 'unplugin';
|
|
3
|
+
|
|
4
|
+
import generateHash from '../lib/generateAbsolutePathHash.js';
|
|
5
|
+
import getClassesTagsFromCss from '../lib/getClassesTagsFromCss.js';
|
|
6
|
+
import replaceGlimmerAst from '../lib/replaceGlimmerAst.js';
|
|
6
7
|
|
|
7
8
|
function* iterateOpcodes(opcodes) {
|
|
8
9
|
for (let instruction of opcodes) {
|
|
@@ -32,6 +33,7 @@ function inflateTagName(tag) {
|
|
|
32
33
|
return 'a';
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
|
|
35
37
|
throw new Error('Unknown tag');
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -83,6 +85,7 @@ export default createUnplugin(({ appDir }) => {
|
|
|
83
85
|
) {
|
|
84
86
|
// 10 - open element
|
|
85
87
|
let existingClassInstruction;
|
|
88
|
+
|
|
86
89
|
for (
|
|
87
90
|
let i = opcodes[0].indexOf(instruction);
|
|
88
91
|
i <= opcodes[0].length;
|
|
@@ -91,8 +94,10 @@ export default createUnplugin(({ appDir }) => {
|
|
|
91
94
|
if (opcodes[0][i][0] === 14 && opcodes[0][i][1] === 0) {
|
|
92
95
|
// 14 - css attribute, 0 - class
|
|
93
96
|
existingClassInstruction = opcodes[0][i];
|
|
97
|
+
|
|
94
98
|
break;
|
|
95
99
|
}
|
|
100
|
+
|
|
96
101
|
if (opcodes[0][i][0] === 12) {
|
|
97
102
|
// 12 - flush element
|
|
98
103
|
break;
|
|
@@ -103,6 +108,7 @@ export default createUnplugin(({ appDir }) => {
|
|
|
103
108
|
existingClassInstruction[2] += ' ' + postfix;
|
|
104
109
|
} else {
|
|
105
110
|
const classInstruction = [14, 0, postfix, undefined];
|
|
111
|
+
|
|
106
112
|
insertions.push([instruction, classInstruction]);
|
|
107
113
|
}
|
|
108
114
|
}
|
|
@@ -111,6 +117,7 @@ export default createUnplugin(({ appDir }) => {
|
|
|
111
117
|
// insert new instructions
|
|
112
118
|
for (let [instruction, classInstruction] of insertions) {
|
|
113
119
|
const index = opcodes[0].indexOf(instruction);
|
|
120
|
+
|
|
114
121
|
opcodes[0].splice(index + 1, 0, classInstruction);
|
|
115
122
|
}
|
|
116
123
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// import { RawSource } from 'webpack-sources';
|
|
2
|
-
import rewriteCss from './lib/rewriteCss.js';
|
|
3
2
|
import { readFile, writeFile } from 'fs/promises';
|
|
4
3
|
import path from 'path';
|
|
5
|
-
|
|
6
|
-
import fsExists from '
|
|
7
|
-
import
|
|
4
|
+
|
|
5
|
+
import fsExists from '../lib/fsExists.js';
|
|
6
|
+
import generateHash from '../lib/generateAbsolutePathHash.js';
|
|
7
|
+
import getFiles from '../lib/getFiles.js';
|
|
8
|
+
import rewriteCss from '../lib/rewriteCss.js';
|
|
8
9
|
|
|
9
10
|
export default class {
|
|
10
11
|
apply(compiler) {
|
|
@@ -22,11 +23,13 @@ export default class {
|
|
|
22
23
|
|
|
23
24
|
// Rewrite the CSS files
|
|
24
25
|
const rewrittenFiles = [];
|
|
26
|
+
|
|
25
27
|
// const rewritenFiles = cssFiles.map((file) => {
|
|
26
28
|
for (let file of cssFiles) {
|
|
27
29
|
if (file.endsWith(`/${path.basename(compiler.context)}.css`)) {
|
|
28
30
|
// import scoped.css into app.css
|
|
29
31
|
let appCss = await readFile(file, 'utf-8');
|
|
32
|
+
|
|
30
33
|
await writeFile(file, `@import "scoped.css";\n${appCss}`);
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -43,6 +46,7 @@ export default class {
|
|
|
43
46
|
) {
|
|
44
47
|
continue;
|
|
45
48
|
}
|
|
49
|
+
|
|
46
50
|
const fileName = path.basename(file);
|
|
47
51
|
const postfix = generateHash(fileName);
|
|
48
52
|
const css = await readFile(file, 'utf-8');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import appCssUnplugin from './app-css-unplugin.js';
|
|
2
|
+
import appJsUnplugin from './app-js-unplugin.js';
|
|
3
|
+
import appScopedcssWebpack from './app-scopedcss-webpack.js';
|
|
4
|
+
import scopedCssUnplugin from './scoped-css-unplugin.js';
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
appCssUnplugin,
|
|
8
|
+
appJsUnplugin,
|
|
9
|
+
appScopedcssWebpack,
|
|
10
|
+
scopedCssUnplugin,
|
|
11
|
+
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { createUnplugin } from 'unplugin';
|
|
2
1
|
import { readFile } from 'fs/promises';
|
|
3
2
|
import path from 'path';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
3
|
+
import { createUnplugin } from 'unplugin';
|
|
4
|
+
|
|
5
|
+
import fsExists from '../lib/fsExists.js';
|
|
6
|
+
import generateHash from '../lib/generateAbsolutePathHash.js';
|
|
7
|
+
import getClassesTagsFromCss from '../lib/getClassesTagsFromCss.js';
|
|
8
|
+
import replaceHbsInJs from '../lib/replaceHbsInJs.js';
|
|
9
|
+
import rewriteCss from '../lib/rewriteCss.js';
|
|
10
|
+
import rewriteHbs from '../lib/rewriteHbs.js';
|
|
10
11
|
|
|
11
12
|
function isJsFile(id) {
|
|
12
13
|
return id.endsWith('.js') || id.endsWith('.ts');
|
|
@@ -22,6 +23,7 @@ async function transformJsFile(code, jsPath) {
|
|
|
22
23
|
|
|
23
24
|
const cssExists = await fsExists(cssPath);
|
|
24
25
|
let css;
|
|
26
|
+
|
|
25
27
|
if (cssExists) {
|
|
26
28
|
css = await readFile(cssPath, 'utf8');
|
|
27
29
|
} else {
|
|
@@ -40,6 +42,7 @@ async function transformJsFile(code, jsPath) {
|
|
|
40
42
|
const { classes, tags } = getClassesTagsFromCss(css);
|
|
41
43
|
const postfix = generateHash(cssPath);
|
|
42
44
|
const rewritten = rewriteHbs(hbs, classes, tags, postfix);
|
|
45
|
+
|
|
43
46
|
return rewritten;
|
|
44
47
|
});
|
|
45
48
|
|
|
@@ -62,6 +65,7 @@ async function transformCssFile(code, id, emitFile) {
|
|
|
62
65
|
|
|
63
66
|
if (jsExists || hbsExists || gtsExists) {
|
|
64
67
|
const postfix = generateHash(id);
|
|
68
|
+
|
|
65
69
|
code = rewriteCss(code, postfix, path.basename(id));
|
|
66
70
|
}
|
|
67
71
|
|
|
@@ -70,6 +74,7 @@ async function transformCssFile(code, id, emitFile) {
|
|
|
70
74
|
fileName: id.replace(path.join(process.cwd(), 'src/'), ''),
|
|
71
75
|
source: code,
|
|
72
76
|
});
|
|
77
|
+
|
|
73
78
|
return '';
|
|
74
79
|
}
|
|
75
80
|
|
|
@@ -79,8 +84,10 @@ export default createUnplugin(() => {
|
|
|
79
84
|
|
|
80
85
|
generateBundle(a, bundle) {
|
|
81
86
|
let cssFiles = [];
|
|
87
|
+
|
|
82
88
|
for (let asset in bundle) {
|
|
83
89
|
const cssAsset = asset.replace('js', 'css');
|
|
90
|
+
|
|
84
91
|
if (!asset.endsWith('js') || !bundle[cssAsset]) {
|
|
85
92
|
continue;
|
|
86
93
|
}
|
package/src/lib/findCssInJs.js
CHANGED
package/src/lib/fsExists.js
CHANGED
|
@@ -1,7 +1,96 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fsSync from 'node:fs';
|
|
2
|
+
|
|
3
|
+
import { findUpSync } from 'find-up';
|
|
2
4
|
import path from 'path';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import generateHash from './generateRelativePathHash.js';
|
|
7
|
+
|
|
8
|
+
export default function generateHashFromAbsolutePath(absolutePath) {
|
|
9
|
+
const modulePath = appPath(absolutePath);
|
|
10
|
+
|
|
11
|
+
return generateHash(modulePath);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* returns the app-module path of the source file
|
|
16
|
+
*
|
|
17
|
+
* This assumes normal ember app conventions
|
|
18
|
+
*
|
|
19
|
+
* which is `<package.json#name>/path-to-file`
|
|
20
|
+
*/
|
|
21
|
+
function appPath(sourcePath) {
|
|
22
|
+
let workspacePath = findWorkspacePath(sourcePath);
|
|
23
|
+
let name = workspacePackageName(sourcePath);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Under embroider builds, the spec-compliant version of the app
|
|
27
|
+
* has all the files under a folder which represents the package name,
|
|
28
|
+
* rather than "app".
|
|
29
|
+
*/
|
|
30
|
+
let packageRelative = sourcePath.replace(workspacePath, '');
|
|
31
|
+
|
|
32
|
+
return `${name}${packageRelative}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const CACHE = new Set();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* For a given source path, if we have seen a
|
|
39
|
+
* source file within the workspace directory,
|
|
40
|
+
* find that workspace directory and return it.
|
|
41
|
+
*/
|
|
42
|
+
function hasSeen(sourcePath) {
|
|
43
|
+
for (let entry of CACHE) {
|
|
44
|
+
if (sourcePath.startsWith(entry)) {
|
|
45
|
+
return entry;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// we have not seen this source path yet
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Populates the "seen" workspace cache,
|
|
55
|
+
* so that we don't hit the file system too often.
|
|
56
|
+
*/
|
|
57
|
+
function findWorkspacePath(sourcePath) {
|
|
58
|
+
let seen = hasSeen(sourcePath);
|
|
59
|
+
|
|
60
|
+
if (seen) {
|
|
61
|
+
return seen;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const packageJsonPath = findUpSync('package.json', {
|
|
65
|
+
cwd: path.dirname(sourcePath),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const workspacePath = path.dirname(packageJsonPath);
|
|
69
|
+
|
|
70
|
+
CACHE.add(workspacePath);
|
|
71
|
+
|
|
72
|
+
return workspacePath;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const MANIFEST_CACHE = new Map();
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* returns the package.json#name for a given sourcePath
|
|
79
|
+
*/
|
|
80
|
+
function workspacePackageName(sourcePath) {
|
|
81
|
+
const workspace = findWorkspacePath(sourcePath);
|
|
82
|
+
|
|
83
|
+
let existing = MANIFEST_CACHE.get(workspace);
|
|
84
|
+
|
|
85
|
+
if (existing) {
|
|
86
|
+
return existing.name;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let buffer = fsSync.readFileSync(path.join(workspace, 'package.json'));
|
|
90
|
+
let content = buffer.toString();
|
|
91
|
+
let json = JSON.parse(content);
|
|
92
|
+
|
|
93
|
+
MANIFEST_CACHE.set(workspace, json);
|
|
94
|
+
|
|
95
|
+
return json.name;
|
|
7
96
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import postcss from 'postcss';
|
|
2
2
|
import parser from 'postcss-selector-parser';
|
|
3
|
+
|
|
3
4
|
import isInsideGlobal from './isInsideGlobal.js';
|
|
4
5
|
|
|
5
6
|
function getClassesAndTags(sel, classes, tags) {
|
|
@@ -21,6 +22,7 @@ export default function getClassesTagsFromCss(css) {
|
|
|
21
22
|
const tags = new Set();
|
|
22
23
|
|
|
23
24
|
const ast = postcss.parse(css);
|
|
25
|
+
|
|
24
26
|
ast.walk((node) => {
|
|
25
27
|
if (node.type === 'rule') {
|
|
26
28
|
getClassesAndTags(node.selector, classes, tags);
|
package/src/lib/getFiles.js
CHANGED
package/src/lib/renameClass.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default function (className, postfix, classesInCss) {
|
|
1
|
+
export default function renameClass(className, postfix, classesInCss) {
|
|
2
2
|
const classes = className.split(/\s+/);
|
|
3
3
|
const renamedClasses = classes
|
|
4
4
|
.filter((c) => c)
|
|
@@ -10,5 +10,6 @@ export default function (className, postfix, classesInCss) {
|
|
|
10
10
|
className.trimStart().trimEnd(),
|
|
11
11
|
renamedClasses
|
|
12
12
|
);
|
|
13
|
+
|
|
13
14
|
return renamedWithPreservedSpaces;
|
|
14
15
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import recast from 'recast';
|
|
2
1
|
import babelParser from '@babel/parser';
|
|
3
|
-
import path from 'path';
|
|
4
2
|
import { readFile } from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import recast from 'recast';
|
|
5
|
+
|
|
5
6
|
import fsExists from './fsExists.js';
|
|
6
7
|
|
|
7
8
|
const parseOptions = {
|
|
@@ -14,6 +15,7 @@ export default async function (script, id, replaceFunction) {
|
|
|
14
15
|
let css;
|
|
15
16
|
|
|
16
17
|
const cssExists = await fsExists(cssPath);
|
|
18
|
+
|
|
17
19
|
if (cssExists) {
|
|
18
20
|
css = await readFile(cssPath, 'utf-8');
|
|
19
21
|
}
|
|
@@ -25,6 +27,7 @@ export default async function (script, id, replaceFunction) {
|
|
|
25
27
|
recast.visit(ast, {
|
|
26
28
|
visitCallExpression(nodePath) {
|
|
27
29
|
const node = nodePath.node;
|
|
30
|
+
|
|
28
31
|
if (
|
|
29
32
|
node.callee.name === 'createTemplateFactory' &&
|
|
30
33
|
node.arguments.length === 1
|
|
@@ -34,6 +37,7 @@ export default async function (script, id, replaceFunction) {
|
|
|
34
37
|
);
|
|
35
38
|
const opcodes = JSON.parse(blockProp.value.value);
|
|
36
39
|
const newOpcodes = replaceFunction(opcodes, css);
|
|
40
|
+
|
|
37
41
|
blockProp.value.value = JSON.stringify(newOpcodes);
|
|
38
42
|
|
|
39
43
|
const fileName = path.basename(cssPath);
|
|
@@ -45,12 +49,15 @@ export default async function (script, id, replaceFunction) {
|
|
|
45
49
|
parseOptions
|
|
46
50
|
);
|
|
47
51
|
const importCssNode = importCss.program.body[0];
|
|
52
|
+
|
|
48
53
|
ast.program.body.unshift(importCssNode);
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
this.traverse(nodePath);
|
|
52
57
|
},
|
|
53
58
|
});
|
|
59
|
+
|
|
54
60
|
const resultScript = recast.print(ast).code;
|
|
61
|
+
|
|
55
62
|
return resultScript;
|
|
56
63
|
}
|