Skip to content

Commit d54b7f4

Browse files
fix executor
1 parent 932d60b commit d54b7f4

2 files changed

Lines changed: 28 additions & 34 deletions

File tree

packages/devextreme-themebuilder/src/modules/post-compiler.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ export function addBasePath(css: string | Buffer, basePath: string): string {
1010
return css.toString().replace(/(url\()("|')?(icons|fonts)/g, `$1$2${normalizedPath}$3`);
1111
}
1212

13-
export function addInfoHeader(
14-
css: string | Buffer,
15-
version: string,
16-
preserveCharsetBoundary = false,
17-
): string {
13+
function buildThemeBuilderInfoHeader(version: string): string {
1814
const generatedBy = '* Generated by the DevExpress ThemeBuilder';
1915
const versionString = `* Version: ${version}`;
2016
const link = '* http://js.devexpress.com/ThemeBuilder/';
2117

22-
const header = `/*${generatedBy}\n${versionString}\n${link}\n*/\n\n`;
18+
return `/*${generatedBy}\n${versionString}\n${link}\n*/\n\n`;
19+
}
20+
21+
export function addInfoHeader(
22+
css: string | Buffer,
23+
version: string,
24+
appendInfoHeaderAfterBody = false,
25+
): string {
26+
const header = buildThemeBuilderInfoHeader(version);
2327
const source = css.toString();
2428
const encoding = '@charset "UTF-8";';
2529

2630
// clean-css may emit @charset immediately followed by :root / @import with no newline.
27-
// Keep backward-compatible output by default (charset + header). In parity mode keep
28-
// @charset as the very first statement and move the info header to the end, so:
29-
// 1) charset decoding stays correct in browsers
30-
// 2) normalized comparison keeps '\n' between @charset and next rule.
3131
const charsetPrefix = /^@charset\s+"utf-8";\s*/i;
3232
const match = source.match(charsetPrefix);
3333
if (match) {
3434
const rest = source.slice(match[0].length).replace(/^\s*/, '');
35-
return preserveCharsetBoundary
35+
return appendInfoHeaderAfterBody
3636
? `${encoding}\n${rest}\n${header}`
3737
: `${encoding}\n${header}${rest}`;
3838
}

packages/nx-infra-plugin/src/executors/scss-build/executor.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ interface BuildDependencies {
3535
cleanCssSanitizeOptions: unknown;
3636
cleanCssDevOptions: unknown;
3737
devextremeVersion: string;
38-
browsersList: string[];
3938
}
4039

4140
type MinifyProfile = 'all' | 'ci';
@@ -52,9 +51,13 @@ function resolveDataUri(filePath: string, svgEncoding?: string): string {
5251
return `data:image/${ext};base64,${data.toString('base64')}`;
5352
}
5453

55-
function createLicenseHeader(fileName: string, version: string): string {
54+
/**
55+
* Same shape as `packages/devextreme/build/gulp/license-header.txt` with
56+
* `gulp-header` `commentType: '*'` (starLicense) — matches legacy Gulp output.
57+
*/
58+
function createStarLicenseHeader(fileName: string, version: string): string {
5659
return [
57-
'/*!',
60+
'/**',
5861
`* DevExtreme (${fileName.replace(/\\/g, '/')})`,
5962
`* Version: ${version}`,
6063
`* Build date: ${new Date().toDateString()}`,
@@ -66,16 +69,13 @@ function createLicenseHeader(fileName: string, version: string): string {
6669
].join('\n');
6770
}
6871

69-
function moveCharsetToTop(css: string): string {
70-
const match = css.match(/@charset\s+[^;]+;\s*/);
71-
if (!match) {
72-
return css;
73-
}
74-
75-
const charset = match[0].trim();
76-
const withoutCharset = css.replace(match[0], '').replace(/^\s+/, '');
77-
78-
return `${charset}\n${withoutCharset}`;
72+
/**
73+
* Mirrors `style-compiler.js`: starLicense prepend, then
74+
* `.replace(/([\s\S]*)(@charset.*?;\s)/, '$2$1')` so `@charset` is the first bytes of output.
75+
*/
76+
function prependLicenseAndMoveCharsetFirst(minifiedCss: string, license: string): string {
77+
const withLicense = `${license}${minifiedCss}`;
78+
return withLicense.replace(/([\s\S]*)(@charset[^;]+;\s*)/, '$2$1');
7979
}
8080

8181
function generateBundleName(theme: string, size: string, color: string, mode?: string): string {
@@ -136,8 +136,6 @@ function loadDependencies(projectRoot: string): BuildDependencies {
136136
),
137137
devextremeVersion: workspaceRequire(path.resolve(projectRoot, '../devextreme/package.json'))
138138
.version,
139-
browsersList: workspaceRequire(path.resolve(projectRoot, '../devextreme/package.json'))
140-
.browserslist,
141139
};
142140
}
143141

@@ -199,12 +197,8 @@ async function compileFile(
199197
});
200198

201199
const postcssFactory = (deps.postcss as unknown as { default?: any }).default || deps.postcss;
202-
const prefixed = await postcssFactory([
203-
deps.autoprefixer({
204-
overrideBrowserslist: deps.browsersList,
205-
}),
206-
]).process(compiled.css, {
207-
from: undefined,
200+
const prefixed = await postcssFactory([deps.autoprefixer()]).process(compiled.css, {
201+
from: sourceFile,
208202
});
209203

210204
const minifierOptions =
@@ -213,8 +207,8 @@ async function compileFile(
213207
const minified = minifier.minify(prefixed.css).styles;
214208

215209
const outFileName = path.basename(sourceFile, '.scss') + '.css';
216-
const withHeader =
217-
createLicenseHeader(outFileName, deps.devextremeVersion) + moveCharsetToTop(minified);
210+
const license = createStarLicenseHeader(outFileName, deps.devextremeVersion);
211+
const withHeader = prependLicenseAndMoveCharsetFirst(minified, license);
218212
await writeFileText(path.join(outputDir, outFileName), withHeader);
219213
}
220214

0 commit comments

Comments
 (0)