Skip to content

Commit e6a4d94

Browse files
Tim Lindvalltimlindvall
Tim Lindvall
authored andcommitted
fix: Updates per PR feedback.
- Use user settings to construct blocks file path. - More granular options merging to build broccoli-concat settings, to ensure sourceMapConfig is accurate. - Use false instead of "SKIP" to disable concat.
1 parent 20048cc commit e6a4d94

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

packages/@css-blocks/ember-app/src/index.ts

+40-11
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,14 @@ const EMBER_ADDON: AddonImplementation<CSSBlocksApplicationAddon> = {
198198
let env = this.env!;
199199

200200
if (type === "css") {
201-
if (!env.isApp || env.config.broccoliConcat === "SKIP") {
201+
if (!env.isApp || env.config.broccoliConcat === false) {
202202
return tree;
203203
}
204204

205-
// Merge default concat options with the options provided by the app.
206-
let concatOptions: BroccoliConcatOptions = Object.assign(
207-
{},
208-
buildDefaultBroccoliConcatOptions(env),
209-
env.config.broccoliConcat || {},
210-
);
211-
212205
// Create the concatenated file...
213206
const concatTree = broccoliConcat(
214207
tree,
215-
concatOptions,
208+
buildBroccoliConcatOptions(env),
216209
);
217210

218211
// Then overwrite the original file with our final build artifact.
@@ -224,19 +217,55 @@ const EMBER_ADDON: AddonImplementation<CSSBlocksApplicationAddon> = {
224217
},
225218
};
226219

220+
/**
221+
* Merge together default and user-provided config options to build the
222+
* configuration for broccoli-concat.
223+
* @param env - The current addon environment. Includes override configs.
224+
* @returns - Merged broccoli concat settings.
225+
*/
226+
function buildBroccoliConcatOptions(env: AddonEnvironment): BroccoliConcatOptions {
227+
const overrides = env.config.broccoliConcat || {};
228+
// The sourcemap config requires special handling because
229+
// things break if extensions or mapCommentType is incorrect.
230+
// We force these to use specific values, but defer to the
231+
// provided options for all other properties.
232+
let sourceMapConfig;
233+
sourceMapConfig = Object.assign(
234+
{},
235+
{
236+
enabled: true,
237+
},
238+
overrides.sourceMapConfig,
239+
{
240+
extensions: ["css"],
241+
mapCommentType: "block",
242+
},
243+
);
244+
// Merge, preferring the user provided options, except for
245+
// the sourceMapConfig, which we merged above.
246+
return Object.assign(
247+
{},
248+
buildDefaultBroccoliConcatOptions(env),
249+
env.config.broccoliConcat,
250+
{
251+
sourceMapConfig,
252+
},
253+
);
254+
}
255+
227256
/**
228257
* Build a default broccoli-concat config, using given enviroment settings.
229258
* @param env - The addon environment.
230259
* @returns - Default broccoli-concat options, accounting for current env settings.
231260
*/
232261
function buildDefaultBroccoliConcatOptions(env: AddonEnvironment): BroccoliConcatOptions {
262+
const cssBlocksOutputFilename = env.config.output || "css-blocks.css";
233263
return {
234-
inputFiles: ["assets/css-blocks.css", `assets/${env.modulePrefix}.css`],
264+
inputFiles: [`assets/${cssBlocksOutputFilename}`, `assets/${env.modulePrefix}.css`],
235265
outputFile: `assets/${env.modulePrefix}.css`,
236266
sourceMapConfig: {
237267
enabled: true,
238268
extensions: ["css"],
239-
inline: true,
240269
mapCommentType: "block",
241270
},
242271
};

packages/@css-blocks/ember-utils/src/options.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ export interface CSSBlocksEmberOptions {
5757
/**
5858
* Options that control the behavior of broccoli-concat, which is used
5959
* to concatenate CSS files together by ember-app during postprocess.
60-
* If this is set to "SKIP", broccoli-concat will *not* run.
60+
* If this is set to false, broccoli-concat will *not* run.
6161
* You'll need to add additional processing to add the CSS Blocks
6262
* compiled content to your final CSS build artifact.
6363
*/
64-
broccoliConcat?: BroccoliConcatOptions | "SKIP";
64+
broccoliConcat?: BroccoliConcatOptions | false;
6565
}
6666

6767
export interface ResolvedCSSBlocksEmberOptions {
@@ -70,7 +70,7 @@ export interface ResolvedCSSBlocksEmberOptions {
7070
analysisOpts: AnalysisOptions;
7171
parserOpts: ParserOptions;
7272
optimization: Partial<OptiCSSOptions>;
73-
broccoliConcat: BroccoliConcatOptions | "SKIP";
73+
broccoliConcat: BroccoliConcatOptions | false;
7474
}
7575

7676
export function getConfig(root: string, isProduction: boolean, options: CSSBlocksEmberOptions): ResolvedCSSBlocksEmberOptions {

0 commit comments

Comments
 (0)