@appdirect/sfb-toolkit 5.0.8 → 6.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/.eslintrc +35 -35
- package/CHANGELOG.md +32 -0
- package/Dockerfile +2 -1
- package/agent/.cursor/rules/sfb-storefront.mdc +17 -0
- package/agent/.cursor/skills/sfb-custom-components/COMPONENT-CATALOG.md +130 -0
- package/agent/.cursor/skills/sfb-custom-components/SKILL.md +43 -0
- package/agent/.cursor/skills/sfb-localization-settings/SKILL.md +29 -0
- package/agent/.cursor/skills/sfb-theme-customize/SKILL.md +25 -0
- package/agent/.cursor/skills/sfb-toolkit-commands/SKILL.md +35 -0
- package/agent/AGENTS.md +160 -0
- package/agent/CLAUDE.md +19 -0
- package/bin/index.js +82 -100
- package/coverage/clover.xml +1921 -335
- package/coverage/coverage-final.json +41 -20
- package/coverage/lcov-report/{controllers/controllers-utils → config}/index.html +19 -19
- package/coverage/lcov-report/config/index.js.html +124 -0
- package/coverage/lcov-report/index.html +108 -78
- package/coverage/lcov-report/{constants → src/constants}/customUserAttributesMock.js.html +12 -12
- package/coverage/lcov-report/{constants → src/constants}/index.html +10 -10
- package/coverage/lcov-report/{constants → src/constants}/pageUrls.js.html +14 -14
- package/coverage/lcov-report/{constants → src/constants}/userMock.js.html +13 -13
- package/coverage/lcov-report/{controllers → src/controllers}/controllers-utils/assetsUtils.js.html +20 -20
- package/coverage/lcov-report/src/controllers/controllers-utils/index.html +131 -0
- package/coverage/lcov-report/src/controllers/controllers-utils/locale.js.html +115 -0
- package/coverage/lcov-report/{controllers → src/controllers}/data-filters/bootstrap-data-filter.js.html +15 -15
- package/coverage/lcov-report/{controllers → src/controllers}/data-filters/call-to-actions-filter.js.html +22 -22
- package/coverage/lcov-report/{controllers → src/controllers}/data-filters/index.html +37 -22
- package/coverage/lcov-report/src/controllers/data-filters/media-url-filter.js.html +394 -0
- package/coverage/lcov-report/{controllers → src/controllers}/index.html +27 -27
- package/coverage/lcov-report/{controllers → src/controllers}/index.js.html +159 -126
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/ResultItem.js.html +43 -43
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/SearchBar.js.html +22 -22
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/index.html +28 -28
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/item.js.html +28 -28
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/container.js.html +31 -31
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/data-view.js.html +29 -29
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/header-view.js.html +35 -38
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/index.html +45 -45
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/search.js.html +54 -54
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/index.html +22 -22
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/pageUrl.js.html +17 -17
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/roleType.js.html +14 -14
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/searchType.js.html +17 -17
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/debounce.js.html +15 -15
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/index.html +20 -20
- package/coverage/lcov-report/{middlewares → src/middlewares}/config.js.html +11 -11
- package/coverage/lcov-report/{middlewares → src/middlewares}/index.html +10 -10
- package/coverage/lcov-report/{tools → src/routes}/index.html +30 -30
- package/coverage/lcov-report/src/routes/media-proxy.js.html +613 -0
- package/coverage/lcov-report/src/tools/compile-styles.js.html +1018 -0
- package/coverage/lcov-report/src/tools/custom-components-export-compat-loader.js.html +745 -0
- package/coverage/lcov-report/src/tools/index.html +371 -0
- package/coverage/lcov-report/src/tools/prompt-questions.js.html +1117 -0
- package/coverage/lcov-report/{tools → src/tools}/proxy-fetch.js.html +15 -15
- package/coverage/lcov-report/src/tools/resolve-components-react.js.html +457 -0
- package/coverage/lcov-report/src/tools/sass-legacy-compat.js.html +1192 -0
- package/coverage/lcov-report/src/tools/toolkit-cli-argv.js.html +226 -0
- package/coverage/lcov-report/src/tools/toolkit-common-fun.js.html +1192 -0
- package/coverage/lcov-report/src/tools/toolkit-common-vars-namespace.js.html +403 -0
- package/coverage/lcov-report/src/tools/toolkit-common-vars.js.html +283 -0
- package/coverage/lcov-report/src/tools/toolkit-components-fun.js.html +1237 -0
- package/coverage/lcov-report/src/tools/toolkit-components-vars.js.html +232 -0
- package/coverage/lcov-report/src/tools/toolkit-install-agent-guidance.js.html +439 -0
- package/coverage/lcov-report/src/tools/toolkit-live-reload.js.html +688 -0
- package/coverage/lcov-report/src/tools/toolkit-path.js.html +184 -0
- package/coverage/lcov-report/src/tools/toolkit-spawn.js.html +199 -0
- package/coverage/lcov-report/src/tools/toolkit-v6-theme-risk.js.html +1039 -0
- package/coverage/lcov-report/src/tools/toolkit-zip-utils.js.html +190 -0
- package/coverage/lcov.info +3356 -727
- package/index.js +40 -20
- package/npm-shrinkwrap.json +19445 -35435
- package/package.json +50 -41
- package/readme.md +23 -1
- package/rspack-components.config.cjs +81 -0
- package/rspack-components.config.prod.cjs +71 -0
- package/rspack.config.cjs +25 -0
- package/rspack.shared.cjs +164 -0
- package/src/controllers/controllers-utils/locale.js +10 -0
- package/src/controllers/data-filters/media-url-filter.js +103 -0
- package/src/controllers/index.js +15 -4
- package/src/front-end-utils/dist/toolbar.bundle.js +1 -2
- package/src/front-end-utils/src/components/header-view.js +0 -1
- package/src/routes/cors.js +29 -0
- package/src/routes/index.js +2 -0
- package/src/routes/media-proxy.js +176 -0
- package/src/tools/compile-styles.js +311 -0
- package/src/tools/compiler-components-prod.js +32 -21
- package/src/tools/compiler-css.js +7 -7
- package/src/tools/custom-components-export-compat-loader.js +220 -0
- package/src/tools/resolve-components-react.js +124 -0
- package/src/tools/sass-legacy-compat.js +369 -0
- package/src/tools/toolkit-checkout.js +3 -6
- package/src/tools/toolkit-cli-argv.js +47 -0
- package/src/tools/toolkit-common-fun.js +66 -18
- package/src/tools/toolkit-common-utils.js +5 -3
- package/src/tools/toolkit-common-vars.js +4 -3
- package/src/tools/toolkit-components-copy.js +6 -4
- package/src/tools/toolkit-components-fun.js +6 -4
- package/src/tools/toolkit-config-setup.js +2 -1
- package/src/tools/toolkit-create.js +5 -7
- package/src/tools/toolkit-import.js +5 -6
- package/src/tools/toolkit-install-agent-guidance-cli.js +24 -0
- package/src/tools/toolkit-install-agent-guidance.js +118 -0
- package/src/tools/toolkit-install.js +8 -8
- package/src/tools/toolkit-live-reload.js +201 -0
- package/src/tools/toolkit-package.js +25 -7
- package/src/tools/toolkit-path.js +33 -0
- package/src/tools/toolkit-setup-e2e.js +2 -1
- package/src/tools/toolkit-setup.js +5 -1
- package/src/tools/toolkit-spawn.js +38 -0
- package/src/tools/toolkit-start.js +98 -54
- package/src/tools/toolkit-storybook.js +38 -19
- package/src/tools/toolkit-update.js +5 -3
- package/src/tools/toolkit-v6-theme-risk.js +318 -0
- package/themes-param.json +1 -0
- package/src/front-end-utils/dist/toolbar.bundle.js.LICENSE.txt +0 -52
- package/src/tools/gulp-tasks.js +0 -80
- package/webpack-components.config.cjs +0 -123
- package/webpack-components.config.prod.cjs +0 -113
- package/webpack.config.cjs +0 -25
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rspack loader: rewrite conflicting `export *` barrels in customComponents/index.js.
|
|
3
|
+
*
|
|
4
|
+
* Webpack + Babel often tolerated:
|
|
5
|
+
* export * from './components';
|
|
6
|
+
* export * from '@appdirect/sfb-theme-components/src/index';
|
|
7
|
+
* when both exported the same name.
|
|
8
|
+
*
|
|
9
|
+
* Rspack ESM linking throws ESModulesLinkingError on that pattern. Expand local
|
|
10
|
+
* `export *` into named re-exports first, then keep the library `export *` so
|
|
11
|
+
* custom names win (same override model themes already rely on).
|
|
12
|
+
*/
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
|
|
16
|
+
const STAR_EXPORT_RE = /export\s*\*\s*from\s*['"]([^'"]+)['"]\s*;?/g;
|
|
17
|
+
const NAMED_DEFAULT_EXPORT_RE =
|
|
18
|
+
/export\s*\{\s*default\s+as\s+(\w+)\s*\}\s*from\s*['"]([^'"]+)['"]\s*;?/g;
|
|
19
|
+
// Bare side-effect imports (e.g. `import 'bootstrap/dist/css/bootstrap.min.css'`).
|
|
20
|
+
// Allow trailing line comments so `import 'x.css'; // bootstrap` is still re-emitted.
|
|
21
|
+
const SIDE_EFFECT_IMPORT_RE =
|
|
22
|
+
/^\s*import\s+['"]([^'"]+)['"]\s*;?\s*(?:\/\/.*)?$/gm;
|
|
23
|
+
const LIBRARY_HINT = "@appdirect/sfb-theme-components";
|
|
24
|
+
|
|
25
|
+
const resolveWithExtensions = (baseDir, request) => {
|
|
26
|
+
const abs = path.resolve(baseDir, request);
|
|
27
|
+
const candidates = [
|
|
28
|
+
abs,
|
|
29
|
+
`${abs}.js`,
|
|
30
|
+
`${abs}.jsx`,
|
|
31
|
+
path.join(abs, "index.js"),
|
|
32
|
+
path.join(abs, "index.jsx")
|
|
33
|
+
];
|
|
34
|
+
for (const candidate of candidates) {
|
|
35
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const toEntryRelativeRequest = (entryDir, absFile) => {
|
|
43
|
+
let rel = path.relative(entryDir, absFile).replace(/\\/g, "/");
|
|
44
|
+
if (!rel.startsWith(".")) {
|
|
45
|
+
rel = `./${rel}`;
|
|
46
|
+
}
|
|
47
|
+
return rel.replace(/\.jsx?$/i, "");
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const toEntryRelativeSideEffectRequest = (entryDir, barrelDir, request) => {
|
|
51
|
+
// Package / absolute specifiers stay as-is (bootstrap CSS, etc.).
|
|
52
|
+
if (!request.startsWith(".")) {
|
|
53
|
+
return request;
|
|
54
|
+
}
|
|
55
|
+
const abs = path.resolve(barrelDir, request);
|
|
56
|
+
let rel = path.relative(entryDir, abs).replace(/\\/g, "/");
|
|
57
|
+
if (!rel.startsWith(".")) {
|
|
58
|
+
rel = `./${rel}`;
|
|
59
|
+
}
|
|
60
|
+
return rel;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const collectNamedExportsFromBarrel = (barrelPath, entryDir) => {
|
|
64
|
+
const source = fs.readFileSync(barrelPath, "utf8");
|
|
65
|
+
const barrelDir = path.dirname(barrelPath);
|
|
66
|
+
const named = [];
|
|
67
|
+
|
|
68
|
+
for (const match of source.matchAll(NAMED_DEFAULT_EXPORT_RE)) {
|
|
69
|
+
const abs = resolveWithExtensions(barrelDir, match[2]);
|
|
70
|
+
if (!abs) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
named.push({
|
|
74
|
+
alias: match[1],
|
|
75
|
+
request: toEntryRelativeRequest(entryDir, abs)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// One level of nested `export * from './…'` (non-library) inside the barrel.
|
|
80
|
+
for (const match of source.matchAll(STAR_EXPORT_RE)) {
|
|
81
|
+
if (match[1].includes(LIBRARY_HINT)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const nested = resolveWithExtensions(barrelDir, match[1]);
|
|
85
|
+
if (nested) {
|
|
86
|
+
named.push(...collectNamedExportsFromBarrel(nested, entryDir));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return named;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Expanding `export * from './components'` into named re-exports skips the
|
|
95
|
+
* barrel module itself. Themes often put CSS (and other side effects) there —
|
|
96
|
+
* re-emit those bare imports on the entry so Rspack still includes them.
|
|
97
|
+
*/
|
|
98
|
+
const collectSideEffectImportsFromBarrel = (barrelPath, entryDir) => {
|
|
99
|
+
const source = fs.readFileSync(barrelPath, "utf8");
|
|
100
|
+
const barrelDir = path.dirname(barrelPath);
|
|
101
|
+
const imports = [];
|
|
102
|
+
const seen = new Set();
|
|
103
|
+
|
|
104
|
+
const add = request => {
|
|
105
|
+
if (!request || seen.has(request)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
seen.add(request);
|
|
109
|
+
imports.push(request);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
for (const match of source.matchAll(SIDE_EFFECT_IMPORT_RE)) {
|
|
113
|
+
add(toEntryRelativeSideEffectRequest(entryDir, barrelDir, match[1]));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const match of source.matchAll(STAR_EXPORT_RE)) {
|
|
117
|
+
if (match[1].includes(LIBRARY_HINT)) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const nested = resolveWithExtensions(barrelDir, match[1]);
|
|
121
|
+
if (nested) {
|
|
122
|
+
for (const request of collectSideEffectImportsFromBarrel(
|
|
123
|
+
nested,
|
|
124
|
+
entryDir
|
|
125
|
+
)) {
|
|
126
|
+
add(request);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return imports;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
module.exports = function customComponentsExportCompatLoader(source) {
|
|
135
|
+
const resourcePath = this.resourcePath || "";
|
|
136
|
+
const normalized = resourcePath.replace(/\\/g, "/");
|
|
137
|
+
if (!normalized.endsWith("/customComponents/index.js")) {
|
|
138
|
+
return source;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const starExports = [...source.matchAll(STAR_EXPORT_RE)];
|
|
142
|
+
if (starExports.length < 2) {
|
|
143
|
+
return source;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const libraryExports = starExports.filter(match =>
|
|
147
|
+
match[1].includes(LIBRARY_HINT)
|
|
148
|
+
);
|
|
149
|
+
const localStars = starExports.filter(
|
|
150
|
+
match => !match[1].includes(LIBRARY_HINT)
|
|
151
|
+
);
|
|
152
|
+
if (!libraryExports.length || !localStars.length) {
|
|
153
|
+
return source;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const entryDir = path.dirname(resourcePath);
|
|
157
|
+
const named = [];
|
|
158
|
+
const seen = new Set();
|
|
159
|
+
const sideEffects = [];
|
|
160
|
+
const seenSideEffects = new Set();
|
|
161
|
+
// Themes often also re-export a local override after the library star:
|
|
162
|
+
// export * from './components';
|
|
163
|
+
// export * from '@appdirect/sfb-theme-components/src/index';
|
|
164
|
+
// export { default as Foo } from './components/foo/Foo';
|
|
165
|
+
// Expanding the local barrel would emit Foo twice → Rspack parse error.
|
|
166
|
+
// Prefer the explicit entry export; skip that name when expanding.
|
|
167
|
+
for (const match of source.matchAll(NAMED_DEFAULT_EXPORT_RE)) {
|
|
168
|
+
seen.add(match[1]);
|
|
169
|
+
}
|
|
170
|
+
for (const match of localStars) {
|
|
171
|
+
const barrel = resolveWithExtensions(entryDir, match[1]);
|
|
172
|
+
if (!barrel) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
for (const entry of collectNamedExportsFromBarrel(barrel, entryDir)) {
|
|
176
|
+
if (seen.has(entry.alias)) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
seen.add(entry.alias);
|
|
180
|
+
named.push(entry);
|
|
181
|
+
}
|
|
182
|
+
for (const request of collectSideEffectImportsFromBarrel(
|
|
183
|
+
barrel,
|
|
184
|
+
entryDir
|
|
185
|
+
)) {
|
|
186
|
+
if (seenSideEffects.has(request)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
seenSideEffects.add(request);
|
|
190
|
+
sideEffects.push(request);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!named.length) {
|
|
195
|
+
return source;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
let rewritten = source;
|
|
199
|
+
for (const match of localStars) {
|
|
200
|
+
rewritten = rewritten.replace(match[0], "");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const sideEffectBlock = sideEffects
|
|
204
|
+
.map(request => `import '${request}';`)
|
|
205
|
+
.join("\n");
|
|
206
|
+
const namedBlock = named
|
|
207
|
+
.map(
|
|
208
|
+
({ alias, request }) =>
|
|
209
|
+
`export { default as ${alias} } from '${request}';`
|
|
210
|
+
)
|
|
211
|
+
.join("\n");
|
|
212
|
+
const prefix = [sideEffectBlock, namedBlock].filter(Boolean).join("\n");
|
|
213
|
+
|
|
214
|
+
rewritten = rewritten.replace(
|
|
215
|
+
libraryExports[0][0],
|
|
216
|
+
`${prefix}\n${libraryExports[0][0]}`
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
return rewritten.replace(/\n{3,}/g, "\n\n");
|
|
220
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const REACT_18 = '18';
|
|
5
|
+
const REACT_16 = '16';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Locate @appdirect/sfb-theme-components/package.json for a theme workspace.
|
|
9
|
+
* Prefer the theme package install, then the workspace root.
|
|
10
|
+
*/
|
|
11
|
+
function findThemeComponentsPackageJson(currentPath, themeName) {
|
|
12
|
+
const candidates = [
|
|
13
|
+
path.join(
|
|
14
|
+
currentPath,
|
|
15
|
+
'themes',
|
|
16
|
+
themeName,
|
|
17
|
+
'node_modules',
|
|
18
|
+
'@appdirect',
|
|
19
|
+
'sfb-theme-components',
|
|
20
|
+
'package.json'
|
|
21
|
+
),
|
|
22
|
+
path.join(
|
|
23
|
+
currentPath,
|
|
24
|
+
'node_modules',
|
|
25
|
+
'@appdirect',
|
|
26
|
+
'sfb-theme-components',
|
|
27
|
+
'package.json'
|
|
28
|
+
)
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
for (const candidate of candidates) {
|
|
32
|
+
if (fs.existsSync(candidate)) {
|
|
33
|
+
return candidate;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readComponentsMajorVersion(packageJsonPath) {
|
|
40
|
+
if (!packageJsonPath) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const { version } = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
45
|
+
if (typeof version !== 'string') {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const major = Number.parseInt(version.split('.')[0], 10);
|
|
49
|
+
return Number.isFinite(major) ? major : null;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Pick React major for the custom-components bundle.
|
|
57
|
+
* Default React 18 (modern sfb-theme-components / any detection failure).
|
|
58
|
+
* React 16 only when components major is known and < 2 (0.x / 1.x).
|
|
59
|
+
*/
|
|
60
|
+
function selectComponentsReactMajor(currentPath, themeName) {
|
|
61
|
+
const packageJsonPath = findThemeComponentsPackageJson(currentPath, themeName);
|
|
62
|
+
const major = readComponentsMajorVersion(packageJsonPath);
|
|
63
|
+
if (major !== null && major < 2) {
|
|
64
|
+
return REACT_16;
|
|
65
|
+
}
|
|
66
|
+
return REACT_18;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getToolkitReactPackageDir(toolkitRoot, reactMajor) {
|
|
70
|
+
const packageName = reactMajor === REACT_16 ? 'react-16' : 'react';
|
|
71
|
+
return path.join(toolkitRoot, 'node_modules', packageName);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getToolkitReactDomPackageDir(toolkitRoot, reactMajor) {
|
|
75
|
+
const packageName = reactMajor === REACT_16 ? 'react-dom-16' : 'react-dom';
|
|
76
|
+
return path.join(toolkitRoot, 'node_modules', packageName);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getToolkitSchedulerPackageDir(toolkitRoot, reactMajor) {
|
|
80
|
+
// Absolute resolve.modules skips nested react-dom/node_modules/scheduler —
|
|
81
|
+
// pin the matching scheduler major next to react/react-dom.
|
|
82
|
+
const packageName = reactMajor === REACT_16 ? 'scheduler-16' : 'scheduler';
|
|
83
|
+
return path.join(toolkitRoot, 'node_modules', packageName);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Absolute resolve.alias so the components bundle uses the toolkit React
|
|
88
|
+
* matching the theme's sfb-theme-components line (not a random hoist).
|
|
89
|
+
*
|
|
90
|
+
* Use `scheduler` (no trailing $) so React 16 subpaths like `scheduler/tracing`
|
|
91
|
+
* resolve under scheduler-16 — `scheduler$` only remaps the bare import and
|
|
92
|
+
* leaves tracing on top-level scheduler@0.23 which no longer ships it.
|
|
93
|
+
*/
|
|
94
|
+
function getComponentsReactResolveAlias(currentPath, themeName, toolkitRoot = path.join(__dirname, '..', '..')) {
|
|
95
|
+
const reactMajor = selectComponentsReactMajor(currentPath, themeName);
|
|
96
|
+
const schedulerDir = getToolkitSchedulerPackageDir(toolkitRoot, reactMajor);
|
|
97
|
+
const alias = {
|
|
98
|
+
react$: getToolkitReactPackageDir(toolkitRoot, reactMajor),
|
|
99
|
+
'react-dom$': getToolkitReactDomPackageDir(toolkitRoot, reactMajor),
|
|
100
|
+
scheduler: schedulerDir
|
|
101
|
+
};
|
|
102
|
+
if (reactMajor === REACT_16) {
|
|
103
|
+
// Explicit subpath aliases keep tracing resolvable even if a bare
|
|
104
|
+
// `scheduler$` entry is merged in elsewhere.
|
|
105
|
+
alias['scheduler/tracing'] = path.join(schedulerDir, 'tracing.js');
|
|
106
|
+
alias['scheduler/tracing-profiling'] = path.join(
|
|
107
|
+
schedulerDir,
|
|
108
|
+
'tracing-profiling.js'
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
reactMajor,
|
|
113
|
+
alias
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
REACT_16,
|
|
119
|
+
REACT_18,
|
|
120
|
+
findThemeComponentsPackageJson,
|
|
121
|
+
readComponentsMajorVersion,
|
|
122
|
+
selectComponentsReactMajor,
|
|
123
|
+
getComponentsReactResolveAlias
|
|
124
|
+
};
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Libsass / gulp-sass compatibility shims for sass-embedded.
|
|
3
|
+
*
|
|
4
|
+
* Published themes still rely on behaviors dart-sass rejects:
|
|
5
|
+
* - @import of non-stylesheet assets (e.g. .ico) — treat as empty
|
|
6
|
+
* - top-level parent selector `&` (libsass treated `&` as empty)
|
|
7
|
+
* - gulp-sass includePaths: entry directory must resolve bare imports like
|
|
8
|
+
* `@import 'pages/foo'` from nested partials
|
|
9
|
+
* - relative / bare imports into `node_modules` (e.g. Bootstrap SCSS)
|
|
10
|
+
*
|
|
11
|
+
* Dart Sass resolves bare `@import`s on the filesystem whenever the containing
|
|
12
|
+
* stylesheet has a `file:` URL, which skips importers. We therefore compile
|
|
13
|
+
* through a custom `legacy-theme:` URL scheme so every theme load goes through
|
|
14
|
+
* this importer (and gets the `&` rewrite).
|
|
15
|
+
*/
|
|
16
|
+
const fs = require("fs");
|
|
17
|
+
const path = require("path");
|
|
18
|
+
const { pathToFileURL, fileURLToPath } = require("url");
|
|
19
|
+
|
|
20
|
+
const NON_STYLESHEET_RE =
|
|
21
|
+
/\.(ico|png|jpe?g|gif|svg|webp|woff2?|ttf|eot)(\?.*)?$/i;
|
|
22
|
+
|
|
23
|
+
const AT_RULE_OPEN_RE =
|
|
24
|
+
/@(?:media|include|supports|if|else(?:\s+if)?|for|while|each|keyframes|font-face|container|layer|mixin|function|charset|import|use|forward|extend|at-root|warn|error|debug)\b/i;
|
|
25
|
+
|
|
26
|
+
const LEGACY_PROTOCOL = "legacy-theme:";
|
|
27
|
+
const EMPTY_PROTOCOL = "sass-legacy-empty:";
|
|
28
|
+
|
|
29
|
+
const toLegacyURL = absPath =>
|
|
30
|
+
new URL(pathToFileURL(path.resolve(absPath)).href.replace(/^file:/, LEGACY_PROTOCOL));
|
|
31
|
+
|
|
32
|
+
const fromLegacyURL = url =>
|
|
33
|
+
fileURLToPath(new URL(url.href.replace(/^legacy-theme:/, "file:")));
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* True when `+` / `>` / `~` / whitespace appear as combinators, not inside
|
|
37
|
+
* functional pseudo args like `:nth-child(2n+1)`.
|
|
38
|
+
*/
|
|
39
|
+
const hasCombinatorOutsideParens = selector => {
|
|
40
|
+
let depth = 0;
|
|
41
|
+
for (let i = 0; i < selector.length; i += 1) {
|
|
42
|
+
const c = selector[i];
|
|
43
|
+
if (c === "(") {
|
|
44
|
+
depth += 1;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (c === ")") {
|
|
48
|
+
depth = Math.max(0, depth - 1);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (depth === 0 && /[\s>+~]/.test(c)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Dart Sass rejects compound `@extend`s (e.g. `.foo.bar`, `.foo:hover`).
|
|
60
|
+
* Rewrite to the documented migration `@extend .foo, .bar` / `.foo, :hover`
|
|
61
|
+
* so published themes still compile.
|
|
62
|
+
*/
|
|
63
|
+
const rewriteCompoundExtends = source =>
|
|
64
|
+
source.replace(/@extend\s+([^;{]+);/g, (full, selectorList) => {
|
|
65
|
+
const trimmed = selectorList.trim();
|
|
66
|
+
if (trimmed.includes(",")) {
|
|
67
|
+
return full;
|
|
68
|
+
}
|
|
69
|
+
// Combinators mean a complex selector — leave for Sass to error/report.
|
|
70
|
+
// Ignore `+` / whitespace inside `:nth-child(2n+1)`-style args.
|
|
71
|
+
if (hasCombinatorOutsideParens(trimmed)) {
|
|
72
|
+
return full;
|
|
73
|
+
}
|
|
74
|
+
const compact = trimmed.replace(/\s+/g, "");
|
|
75
|
+
// .class / #id / :pseudo / ::pseudo (optional args)
|
|
76
|
+
const simples = compact.match(
|
|
77
|
+
/([.#][-\w]+|:{1,2}[-\w]+(?:\([^)]*\))?)/g
|
|
78
|
+
);
|
|
79
|
+
if (simples && simples.length > 1 && simples.join("") === compact) {
|
|
80
|
+
return `@extend ${simples.join(", ")};`;
|
|
81
|
+
}
|
|
82
|
+
return full;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Strip parent selectors that libsass accepted at "non-selector" depth
|
|
87
|
+
* (e.g. `&.bar` inside `@include media-breakpoint-down` / `@media` at the
|
|
88
|
+
* root). Selector nests like `.a { &.b }` are preserved.
|
|
89
|
+
*/
|
|
90
|
+
const stripRootParentSelectors = source => {
|
|
91
|
+
let out = "";
|
|
92
|
+
let i = 0;
|
|
93
|
+
const n = source.length;
|
|
94
|
+
/** @type {Array<'selector' | 'atrule' | 'mixin'>} */
|
|
95
|
+
const stack = [];
|
|
96
|
+
|
|
97
|
+
const prevChunk = () => {
|
|
98
|
+
const cut = Math.max(
|
|
99
|
+
out.lastIndexOf("{"),
|
|
100
|
+
out.lastIndexOf("}"),
|
|
101
|
+
out.lastIndexOf(";")
|
|
102
|
+
);
|
|
103
|
+
return out.slice(cut + 1).trim();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
while (i < n) {
|
|
107
|
+
const c = source[i];
|
|
108
|
+
|
|
109
|
+
if (c === "/" && source[i + 1] === "/") {
|
|
110
|
+
while (i < n && source[i] !== "\n") {
|
|
111
|
+
out += source[i++];
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (c === "/" && source[i + 1] === "*") {
|
|
116
|
+
out += source[i++] + source[i++];
|
|
117
|
+
while (i < n && !(source[i - 1] === "*" && source[i] === "/")) {
|
|
118
|
+
out += source[i++];
|
|
119
|
+
}
|
|
120
|
+
if (i < n) {
|
|
121
|
+
out += source[i++];
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (c === '"' || c === "'") {
|
|
126
|
+
const quote = source[i++];
|
|
127
|
+
out += quote;
|
|
128
|
+
while (i < n && source[i] !== quote) {
|
|
129
|
+
if (source[i] === "\\") {
|
|
130
|
+
out += source[i++];
|
|
131
|
+
if (i < n) {
|
|
132
|
+
out += source[i++];
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
out += source[i++];
|
|
137
|
+
}
|
|
138
|
+
if (i < n) {
|
|
139
|
+
out += source[i++];
|
|
140
|
+
}
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (c === "{") {
|
|
145
|
+
const chunk = prevChunk();
|
|
146
|
+
// `&` inside @mixin/@function is bound at @include time — never strip.
|
|
147
|
+
if (/@(?:mixin|function)\b/i.test(chunk)) {
|
|
148
|
+
stack.push("mixin");
|
|
149
|
+
} else if (AT_RULE_OPEN_RE.test(chunk)) {
|
|
150
|
+
stack.push("atrule");
|
|
151
|
+
} else {
|
|
152
|
+
stack.push("selector");
|
|
153
|
+
}
|
|
154
|
+
out += c;
|
|
155
|
+
i += 1;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (c === "}") {
|
|
160
|
+
stack.pop();
|
|
161
|
+
out += c;
|
|
162
|
+
i += 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (c === "&") {
|
|
167
|
+
const selectorDepth = stack.filter(frame => frame === "selector").length;
|
|
168
|
+
const mixinDepth = stack.filter(frame => frame === "mixin").length;
|
|
169
|
+
// Only strip libsass-style top-level `&` under @media/@include/etc.
|
|
170
|
+
if (selectorDepth === 0 && mixinDepth === 0) {
|
|
171
|
+
i += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
out += c;
|
|
177
|
+
i += 1;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return out;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/** Apply all source-level libsass compat rewrites. */
|
|
184
|
+
const applyLegacySourceRewrites = source =>
|
|
185
|
+
rewriteCompoundExtends(stripRootParentSelectors(source));
|
|
186
|
+
|
|
187
|
+
const syntaxFor = filePath =>
|
|
188
|
+
(/\.sass$/i.test(filePath) ? "indented" : "scss");
|
|
189
|
+
|
|
190
|
+
const resolveFromBase = (base, urlPath) => {
|
|
191
|
+
const rel = urlPath.replace(/\\/g, "/");
|
|
192
|
+
const basename = path.basename(rel);
|
|
193
|
+
const dirname = path.dirname(rel);
|
|
194
|
+
// Libsass directory imports: `@import 'pages'` → pages/_index.scss / index.scss
|
|
195
|
+
const candidates = [
|
|
196
|
+
path.resolve(base, rel),
|
|
197
|
+
path.resolve(base, `${rel}.scss`),
|
|
198
|
+
path.resolve(base, `${rel}.sass`),
|
|
199
|
+
path.resolve(base, `${rel}.css`),
|
|
200
|
+
path.resolve(base, dirname, `_${basename}.scss`),
|
|
201
|
+
path.resolve(base, dirname, `_${basename}.sass`),
|
|
202
|
+
path.resolve(base, dirname, `_${basename}.css`),
|
|
203
|
+
path.resolve(base, rel, "_index.scss"),
|
|
204
|
+
path.resolve(base, rel, "index.scss"),
|
|
205
|
+
path.resolve(base, rel, "_index.sass"),
|
|
206
|
+
path.resolve(base, rel, "index.sass"),
|
|
207
|
+
path.resolve(base, rel, "_index.css"),
|
|
208
|
+
path.resolve(base, rel, "index.css")
|
|
209
|
+
];
|
|
210
|
+
for (const candidate of candidates) {
|
|
211
|
+
try {
|
|
212
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
213
|
+
return candidate;
|
|
214
|
+
}
|
|
215
|
+
} catch (_err) {
|
|
216
|
+
// ignore unreadable candidates
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const containingDir = containingUrl => {
|
|
223
|
+
if (!containingUrl) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
if (containingUrl.protocol === LEGACY_PROTOCOL) {
|
|
227
|
+
return path.dirname(fromLegacyURL(containingUrl));
|
|
228
|
+
}
|
|
229
|
+
if (containingUrl.protocol === "file:") {
|
|
230
|
+
return path.dirname(fileURLToPath(containingUrl));
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const themeRootFromPath = filePath => {
|
|
236
|
+
const match = path.resolve(filePath).match(/^(.*[/\\]themes[/\\][^/\\]+)/);
|
|
237
|
+
return match ? match[1] : null;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const packagePathAfterNodeModules = url => {
|
|
241
|
+
const normalized = url.replace(/\\/g, "/");
|
|
242
|
+
const marker = "node_modules/";
|
|
243
|
+
const idx = normalized.lastIndexOf(marker);
|
|
244
|
+
if (idx === -1) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
return normalized.slice(idx + marker.length);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const resolveStylesheetUrl = (url, context, loadPaths) => {
|
|
251
|
+
if (!url || url.startsWith("sass:")) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
if (NON_STYLESHEET_RE.test(url)) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const bases = [];
|
|
259
|
+
const fromContaining = containingDir(context && context.containingUrl);
|
|
260
|
+
if (fromContaining) {
|
|
261
|
+
bases.push(fromContaining);
|
|
262
|
+
}
|
|
263
|
+
for (const loadPath of loadPaths) {
|
|
264
|
+
bases.push(loadPath);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
for (const base of bases) {
|
|
268
|
+
const resolved = resolveFromBase(base, url);
|
|
269
|
+
// Allow node_modules: themes import Bootstrap (and its nested partials) from there.
|
|
270
|
+
if (resolved) {
|
|
271
|
+
return resolved;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Relative `../../node_modules/pkg/...` may point at the project root while the
|
|
276
|
+
// package only exists under themes/<name>/node_modules — resolve by package path.
|
|
277
|
+
const pkgPath = packagePathAfterNodeModules(url);
|
|
278
|
+
if (pkgPath) {
|
|
279
|
+
const nmRoots = [];
|
|
280
|
+
if (fromContaining) {
|
|
281
|
+
const themeRoot = themeRootFromPath(fromContaining);
|
|
282
|
+
if (themeRoot) {
|
|
283
|
+
nmRoots.push(path.join(themeRoot, "node_modules"));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
nmRoots.push(path.join(process.cwd(), "node_modules"));
|
|
287
|
+
for (const nmRoot of nmRoots) {
|
|
288
|
+
const resolved = resolveFromBase(nmRoot, pkgPath);
|
|
289
|
+
if (resolved) {
|
|
290
|
+
return resolved;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return null;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @param {string[]} loadPaths
|
|
300
|
+
* @returns {import('sass-embedded').Importer[]}
|
|
301
|
+
*/
|
|
302
|
+
const createLegacySassImporters = (loadPaths = []) => {
|
|
303
|
+
const normalizedLoadPaths = loadPaths.map(p => path.resolve(p));
|
|
304
|
+
|
|
305
|
+
return [
|
|
306
|
+
{
|
|
307
|
+
canonicalize(url, context) {
|
|
308
|
+
if (NON_STYLESHEET_RE.test(url)) {
|
|
309
|
+
return new URL(EMPTY_PROTOCOL + encodeURIComponent(url));
|
|
310
|
+
}
|
|
311
|
+
const resolved = resolveStylesheetUrl(url, context, normalizedLoadPaths);
|
|
312
|
+
if (!resolved) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
return toLegacyURL(resolved);
|
|
316
|
+
},
|
|
317
|
+
load(canonicalUrl) {
|
|
318
|
+
if (canonicalUrl.protocol === EMPTY_PROTOCOL) {
|
|
319
|
+
return { contents: "", syntax: "scss" };
|
|
320
|
+
}
|
|
321
|
+
if (canonicalUrl.protocol !== LEGACY_PROTOCOL) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
const filePath = fromLegacyURL(canonicalUrl);
|
|
325
|
+
const contents = applyLegacySourceRewrites(
|
|
326
|
+
fs.readFileSync(filePath, "utf8")
|
|
327
|
+
);
|
|
328
|
+
return { contents, syntax: syntaxFor(filePath) };
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
];
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Options for compiling one theme SCSS entry with libsass-compatible behavior.
|
|
336
|
+
* Caller should use `sass.compileString(strippedEntrySource, { ...opts })`.
|
|
337
|
+
* @param {string} entryPath
|
|
338
|
+
*/
|
|
339
|
+
const legacyCompileOptionsForEntry = entryPath => {
|
|
340
|
+
const absolute = path.resolve(entryPath);
|
|
341
|
+
// Include cwd so themes can `@import 'themes/<name>/…'` the way node-sass did.
|
|
342
|
+
// Include theme + project node_modules for Bootstrap-style bare/relative imports.
|
|
343
|
+
const loadPaths = [path.dirname(absolute), process.cwd()];
|
|
344
|
+
const themeRoot = themeRootFromPath(absolute);
|
|
345
|
+
if (themeRoot) {
|
|
346
|
+
loadPaths.push(path.join(themeRoot, "node_modules"));
|
|
347
|
+
}
|
|
348
|
+
loadPaths.push(path.join(process.cwd(), "node_modules"));
|
|
349
|
+
return {
|
|
350
|
+
// Custom scheme so nested @imports hit the importer (not raw filesystem).
|
|
351
|
+
url: toLegacyURL(absolute),
|
|
352
|
+
importers: createLegacySassImporters(loadPaths)
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const readLegacyEntrySource = entryPath =>
|
|
357
|
+
applyLegacySourceRewrites(fs.readFileSync(entryPath, "utf8"));
|
|
358
|
+
|
|
359
|
+
module.exports = {
|
|
360
|
+
NON_STYLESHEET_RE,
|
|
361
|
+
stripRootParentSelectors,
|
|
362
|
+
rewriteCompoundExtends,
|
|
363
|
+
applyLegacySourceRewrites,
|
|
364
|
+
createLegacySassImporters,
|
|
365
|
+
legacyCompileOptionsForEntry,
|
|
366
|
+
readLegacyEntrySource,
|
|
367
|
+
toLegacyURL,
|
|
368
|
+
fromLegacyURL
|
|
369
|
+
};
|